Re: [GENERAL] create a table inside a function

2009-06-25 Thread Frank Heikens
A very simple and incomplete example: CREATE OR REPLACE FUNCTION new_table(int) returns bool AS $$ BEGIN IF $1 = 1 THEN EXECUTE 'CREATE TABLE x()'; ELSIF $1 = 2 THEN EXECUTE 'CREATE TABLE y()'; ELSE EXECUTE 'CREATE TABLE z()'

Re: [GENERAL] create a table inside a function

2009-06-25 Thread Alvaro Herrera
Alain Roger escribió: > IF (outResult = 1) THEN > > return true; > > ELSE > > EXECUTE 'create table sw.tmp_import (id serial NOT NULL CONSTRAINT id_key > > PRIMARY KEY, software VARCHAR(1024), barcode VARCHAR(10), username > > VARCHAR(1024), area VARCHAR(512), locality VARCHAR(512)) WITH > > (OI

Re: [GENERAL] create a table inside a function

2009-06-25 Thread Adrian Klaver
On Thursday 25 June 2009 6:29:10 am Alain Roger wrote: > I'm confused now because if i try my SQL command alone it works without any > problem, but in the following pglSQL code, it does not :-( What is the error? > > IF (outResult = 1) THEN > > > return true; > > ELSE > > EXECUTE 'create table

Re: [GENERAL] create a table inside a function

2009-06-25 Thread Alain Roger
I'm confused now because if i try my SQL command alone it works without any problem, but in the following pglSQL code, it does not :-( IF (outResult = 1) THEN > return true; > ELSE > EXECUTE 'create table sw.tmp_import (id serial NOT NULL CONSTRAINT id_key > PRIMARY KEY, software VARCHAR(1024),

Re: [GENERAL] create a table inside a function

2009-06-25 Thread Alain Roger
This is what i did at the beginning and it did not work. But now i've just discovered that my create table command was wrong...so it's ok. :-) thx. A. On Thu, Jun 25, 2009 at 3:01 PM, Frank Heikens wrote: > A very simple and incomplete example: > > CREATE OR REPLACE FUNCTION new_table(int) retur

Re: [GENERAL] create a table inside a function

2009-06-25 Thread hubert depesz lubaczewski
On Thu, Jun 25, 2009 at 02:53:59PM +0200, Alain Roger wrote: > i would like to execute the following SQL command into a function based on > some IF, END IF tests before. > how can i do that ? 1. you can use execute in pl/pgsql. 2. if your ifs are basically testing if the table exists - you might w