PL/PgSQL Create/Drop Table Issue

From: Database Administrator <dba(at)vilaj(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: PL/PgSQL Create/Drop Table Issue
Date: 2003-05-09 14:26:20
Message-ID: 3EBBBA8C.70205@vilaj.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

I believe I've found a problem in creating and dropping tables within
PL/PgSQL functions. If you create a table, do some work with it, then
drop it from within a PL/PgSQL function, it will work correctly the
first time through. On subsequent executions of the function, however,
attempting to insert data into the table will result in an error. The
error report follows as does a script which demonstrates the issue clearly.

==== START OF ERROR OUTPUT ====

psql:./test_temp_table.sql:33: WARNING: Error occurred while executing
PL/pgSQL function test_temp_table
psql:./test_temp_table.sql:33: WARNING: line 5 at SQL statement
psql:./test_temp_table.sql:33: ERROR: pg_class_aclcheck: relation
3326289 not found

==== END OF ERROR OUTPUT ====

==== START OF SCRIPT ====

CREATE TABLE my_permanent_table (
key_value serial NOT NULL PRIMARY KEY,
statement text NOT NULL);

CREATE OR REPLACE FUNCTION test_temp_table()
RETURNS boolean AS '
BEGIN
-- NOTE: regular and temporary tables both affected the same

CREATE TEMPORARY TABLE my_temp_table (
statement text NOT NULL);

INSERT INTO my_temp_table (statement)
VALUES (''We can''''t play this game anymore...'');

INSERT INTO my_temp_table (statement)
VALUES (''...but can we still be friends?'');

INSERT INTO my_permanent_table (statement)
SELECT statement
FROM my_temp_table;

DROP TABLE my_temp_table;

RETURN true;
END;
' LANGUAGE 'plpgsql';

SELECT test_temp_table();

SELECT key_value,
statement
FROM my_permanent_table;

SELECT test_temp_table();

==== END OF SCRIPT ====

==== VERSION/PLATFORM INFO ====

PostgreSQL 7.3.2 on powerpc-apple-darwin6.3, compiled by GCC gcc (GCC)
3.1 20020420 (prerelease)

Also tested on Debian Linux 3.0.x on Intel x86 with same result.

=================================

Thanks for looking into this.

--
Database Administrator, vilaj.com, LLC
<http://www.vilaj.com/>

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Bugs 2003-05-09 16:12:34 segmentation fault in libpq (PHP CLI)
Previous Message Tom Lane 2003-05-09 13:30:12 Re: An unresolved performance problem.