Unable to CREATE SCHEMA and INSERT data in table in that schema in same EXECUTE - Mailing list pgsql-general

From vibhuti nataraj
Subject Unable to CREATE SCHEMA and INSERT data in table in that schema in same EXECUTE
Date
Msg-id CAMFwpEs0WAzed-0pFDEDKGnBKsC01ZABYEsg7xfKJY+J1rdnTA@mail.gmail.com
Whole thread Raw
Responses Re: Unable to CREATE SCHEMA and INSERT data in table in that schema in same EXECUTE  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hi,

I am using server 9.0.4, I am trying to
1. Create a new schema,
2. Create a table under that schema, and 
3. Insert data in that schema,
In the same EXECUTE and its failing. If I try

CREATE OR REPLACE FUNCTION pg_temp.test( ) 
RETURNS void LANGUAGE plpgsql AS 
$BODY$
BEGIN
EXECUTE 'CREATE SCHEMA test; CREATE TABLE test.t (id integer ); INSERT INTO test.t (id) VALUES (0);';
END;
$BODY$;

select pg_temp.test( );

I get a failure with the following error.
ERROR:  schema "test" does not exist
LINE 1: ...t; CREATE TABLE test.t (id integer ); INSERT INTO test.t (id...
                                                             ^
However, the same thing works if use two EXECUTEs in the same transaction.
CREATE OR REPLACE FUNCTION pg_temp.test( ) 
RETURNS void LANGUAGE plpgsql AS 
$BODY$
BEGIN
EXECUTE 'CREATE SCHEMA test; CREATE TABLE test.t (id integer );';
EXECUTE 'INSERT INTO test.t (id) VALUES (0);';
END;
$BODY$;

 select pg_temp.test( );


 Unable to understand the difference between the two. Will appreciate if someone can help me here.

Thanks.
Best regards,
Vibhuti


pgsql-general by date:

Previous
From: Michael Paquier
Date:
Subject: Re: My Experiment of PG crash when dealing with huge amount of data
Next
From: Tom Lane
Date:
Subject: Re: Unable to CREATE SCHEMA and INSERT data in table in that schema in same EXECUTE