DDL+SQL in PL/pgSQL EXECUTE

From: Vlad Arkhipov <arhipov(at)dc(dot)baikal(dot)ru>
To: pgsql-hackers(at)postgresql(dot)org
Subject: DDL+SQL in PL/pgSQL EXECUTE
Date: 2009-03-18 10:15:36
Message-ID: 49C0C9C8.9020007@dc.baikal.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Is it a bug or by design? I could not find what behaviour is correct for
these statements in PL/pgSQL:

This function just executes a string.
CREATE OR REPLACE FUNCTION _EXEC(query VARCHAR)
RETURNS VOID AS $$
BEGIN
EXECUTE query;
END;
$$ LANGUAGE 'plpgsql';

1. Works ok.
BEGIN WORK;
SELECT _EXEC('CREATE TABLE T(ID INTEGER); CREATE INDEX T_IDX ON T(ID)');
ROLLBACK;

2. Works ok.
BEGIN WORK;
SELECT _EXEC('CREATE TABLE T(ID INTEGER); ALTER TABLE T ADD COLUMN ID2
INTEGER; CREATE INDEX T_IDX2 ON T(ID2)');
ROLLBACK;

3. ERROR: relation "t" does not exist
SELECT _EXEC('CREATE TABLE T(ID INTEGER); INSERT INTO T(ID) VALUES (1)');

4. Inserts NULL value into ID column instead of default 10.
BEGIN WORK;
CREATE TABLE T(ID INTEGER);
SELECT _EXEC('ALTER TABLE T ALTER COLUMN ID SET DEFAULT(10); INSERT INTO
T DEFAULT VALUES');
SELECT * FROM T;

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2009-03-18 12:35:55 cs_CZ vs regression tests, part N
Previous Message Dave Page 2009-03-18 09:28:47 Re: Path separator