From: | Sondaar Roelof <roelof(dot)sondaar(at)scania(dot)com> |
---|---|
To: | "'Seethalakshmi VB'" <seethalakshmi(dot)vb(at)majoris(dot)com>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Creating tables from within functions |
Date: | 2003-01-29 08:16:23 |
Message-ID: | B659C5A6EF67D5119430006097487147329947@sv7007b.nl.scania.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hello,
Try this:
CREATE FUNCTION _testcreate () RETURNS text AS '
BEGIN
CREATE TABLE switch_table2 (switch_id varchar(32),
selection_name varchar(100));
RETURN ''true'';
END;
' language 'plpgsql';
SELECT _testcreate();
Result:
snlsor=# SELECT _testcreate();
_testcreate
-------------
true
(1 row)
me=# \d
List of relations
Name | Type | Owner
----------------+----------+--------
switch_table2 | table | me
> -----Original Message-----
> From: Seethalakshmi VB [SMTP:seethalakshmi(dot)vb(at)majoris(dot)com]
> Sent: vrijdag 24 januari 2003 09:37
> To: pgsql-sql(at)postgresql(dot)org
> Subject: [SQL] Creating tables from within functions
>
> Is it possible to issue a CREATE TABLE statement from inside of a
> PostgreSQL
> function? If not, then how about from within a PL/pgSQL function? I have
> tried a lot of different permutations but can't seem to get it to compile
> and/or run cleanly. For example, consider:
>
> CREATE FUNCTION _testcreate () RETURNS text AS '
> BEGIN
> CREATE TABLE switch_table2 (switch_id varchar(32),
> selection_name varchar(100));
> end;
> ' language 'plpgsql';
>
> What is wrong with this? What type should be returned? Or perhaps it is
> simply not possible to create a table from within a function?
>
> Please give me the reply soon as possible
> Thanks!
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2003-01-29 08:25:57 | Re: Filter function |
Previous Message | Sondaar Roelof | 2003-01-29 08:05:52 | COPY use in function with variable file name |