Re: [GENERAL] plpgsql; execute query inside exists

2011-10-18 Thread Alban Hertroys
On 18 October 2011 09:57, wrote: > Hi, > > Thanks for the reply! > But I don't want to check if the table exists, I want to see the > result of the SELECT query, if a row presence or not. So you want to check that the table contains data? In that case it makes no sense to create the table if it

Re: [GENERAL] plpgsql; execute query inside exists

2011-10-18 Thread jozsef . kurucz
Hi, Thanks for the reply! But I don't want to check if the table exists, I want to see the result of the SELECT query, if a row presence or not. The tmp_tbl is a dynamic generated table name, but when I write the code without EXECUTE, I get syntax error too. In this case how can I check if a SELEC

Re: [GENERAL] plpgsql; execute query inside exists

2011-10-17 Thread Merlin Moncure
On Mon, Oct 17, 2011 at 10:28 AM, Alban Hertroys wrote: > On 17 October 2011 16:24, Merlin Moncure wrote: >> On Mon, Oct 17, 2011 at 8:44 AM, Alban Hertroys wrote: >>> On 17 October 2011 15:20, Merlin Moncure wrote: A better way to do this is to query information_schema: PERFORM

Re: [GENERAL] plpgsql; execute query inside exists

2011-10-17 Thread Alban Hertroys
On 17 October 2011 16:24, Merlin Moncure wrote: > On Mon, Oct 17, 2011 at 8:44 AM, Alban Hertroys wrote: >> On 17 October 2011 15:20, Merlin Moncure wrote: >>> A better way to do this is to query information_schema: >>> >>> PERFORM 1 FROM information_schema.tables where schema_name = x and >>> t

Re: [GENERAL] plpgsql; execute query inside exists

2011-10-17 Thread Merlin Moncure
On Mon, Oct 17, 2011 at 8:44 AM, Alban Hertroys wrote: > On 17 October 2011 15:20, Merlin Moncure wrote: >> A better way to do this is to query information_schema: >> >> PERFORM 1 FROM information_schema.tables where schema_name = x and >> table_name = y; >> >> IF FOUND THEN >>  CREATE TABLE ...

Re: [GENERAL] plpgsql; execute query inside exists

2011-10-17 Thread Alban Hertroys
On 17 October 2011 15:20, Merlin Moncure wrote: > A better way to do this is to query information_schema: > > PERFORM 1 FROM information_schema.tables where schema_name = x and > table_name = y; > > IF FOUND THEN >  CREATE TABLE ... > END IF; > > (there is a race condition in the above code -- do

Re: [GENERAL] plpgsql; execute query inside exists

2011-10-17 Thread Merlin Moncure
On Mon, Oct 17, 2011 at 8:20 AM, Merlin Moncure wrote: > On Mon, Oct 17, 2011 at 2:32 AM,   wrote: >> Hi there, >> >> I would like to use EXISTS in a small plpgsql function but I always >> get a "syntax error". How can I execute a query inside the >> EXISTS function? >> >> >> >> IF NOT EXISTS(EXEC

Re: [GENERAL] plpgsql; execute query inside exists

2011-10-17 Thread Merlin Moncure
On Mon, Oct 17, 2011 at 2:32 AM, wrote: > Hi there, > > I would like to use EXISTS in a small plpgsql function but I always > get a "syntax error". How can I execute a query inside the > EXISTS function? > > > > IF NOT EXISTS(EXECUTE 'SELECT * FROM '|| tmp_tbl) >   THEN >      CREATE TABLE tt();

[GENERAL] plpgsql; execute query inside exists

2011-10-17 Thread jozsef . kurucz
Hi there, I would like to use EXISTS in a small plpgsql function but I always get a "syntax error". How can I execute a query inside the EXISTS function? IF NOT EXISTS(EXECUTE 'SELECT * FROM '|| tmp_tbl) THEN CREATE TABLE tt(); ERROR: syntax error at or near "EXECUTE" LINE 1: SELE