Problem with pg_dump and functions
От
Mark Dalphin
Тема
Problem with pg_dump and functions
Дата
Msg-id
37F263ED.3CFE6A46@amgen.com
Список
============================================================================
POSTGRESQL BUG REPORT TEMPLATE
============================================================================
Your name : Mark Dalphin
Your email address : mdalphin@amgen.com
System Configuration
---------------------
Architecture (example: Intel Pentium) : SGI Octane
Operating System (example: Linux 2.0.26 ELF) : Irix 6.5
PostgreSQL version (example: PostgreSQL-6.5.1): PostgreSQL-6.5.1 (patched)
Compiler used (example: gcc 2.8.0) : Native cc
Please enter a FULL description of your problem:
------------------------------------------------
pg_dump of a database outputs CREATE TABLE commands,
followed by CREATE FUNCTION commands.
As a "DEFAULT" condition in some of my tables, I call a
function. When I restore from a pg_dump, I find that
many CREATE TABLE commands fail as the DEFAULT function
does not exist.
Please describe a way to repeat the problem. Please try to provide a
concise reproducible example, if at all possible:
----------------------------------------------------------------------
First create a database with a function:
CREATE FUNCTION "gettimestamp" ( ) RETURNS timestamp AS '
DECLARE
cur_time timestamp;
BEGIN
cur_time = ''now'';
RETURN cur_time;
END;
' LANGUAGE 'plpgsql';
CREATE TABLE test (
key int PRIMARY KEY,
theTime timestamp DEFAULT getTimeStamp()
);
Exit the database and dump it:
pg_dump postgres > postgres.dump
Dump looks like this:
\connect - postgres
CREATE TABLE "test" (
"key" int4 NOT NULL,
"thetime" timestamp DEFAULT gettimestamp ( ));
CREATE FUNCTION "plpgsql_call_handler" ( ) RETURNS opaque AS
'/usr/compbio/pgsql/lib/plpgsql.so' LANGUAGE 'C';
CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql' HANDLER "plpgsql_call_handler"
LANCOMPILER 'PL/pgSQL';
CREATE FUNCTION "gettimestamp" ( ) RETURNS timestamp AS '
DECLARE
cur_time timestamp;
BEGIN
cur_time = ''now'';
RETURN cur_time;
END;
' LANGUAGE 'plpgsql';
COPY "test" FROM stdin;
\.
CREATE UNIQUE INDEX "test_pkey" on "test" using btree ( "key" "int4_ops" );
Recreate the database and restore the dumped data:
destroydb postgres
createdb postgres
psql -e < postgres.dump
Errors look like this:
\connect - postgres
connecting as new user: postgres
CREATE TABLE "test" (
"key" int4 NOT NULL,
"thetime" timestamp DEFAULT gettimestamp ( ));
QUERY: CREATE TABLE "test" (
"key" int4 NOT NULL,
"thetime" timestamp DEFAULT gettimestamp ( ));
ERROR: No such function 'gettimestamp' with the specified attributes
CREATE FUNCTION "plpgsql_call_handler" ( ) RETURNS opaque AS
'/usr/compbio/pgsql/lib/plpgsql.so' LANGUAGE 'C';
QUERY: CREATE FUNCTION "plpgsql_call_handler" ( ) RETURNS opaque AS
'/usr/compbio/pgsql/lib/plpgsql.so' LANGUAGE 'C';
ERROR: ProcedureCreate: procedure plpgsql_call_handler already exists with same
arguments
CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql' HANDLER "plpgsql_call_handler"
LANCOMPILER 'PL/pgSQL';
QUERY: CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql' HANDLER
"plpgsql_call_handler" LANCOMPILER 'PL/pgSQL';
ERROR: Language plpgsql already exists
CREATE FUNCTION "gettimestamp" ( ) RETURNS timestamp AS '
DECLARE
cur_time timestamp;
BEGIN
cur_time = ''now'';
RETURN cur_time;
END;
' LANGUAGE 'plpgsql';
QUERY: CREATE FUNCTION "gettimestamp" ( ) RETURNS timestamp AS '
DECLARE
cur_time timestamp;
BEGIN
cur_time = ''now'';
RETURN cur_time;
END;
' LANGUAGE 'plpgsql';
CREATE
COPY "test" FROM stdin;
QUERY: COPY "test" FROM stdin;
ERROR: COPY command failed. Class test does not exist.
\.
\? -- help
\a -- toggle field-alignment (currently on)
\C [] -- set html3 caption (currently '')
\connect -- connect to new database (currently 'postgres')
\copy table {from | to}
\d [В списке pgsql-bugs по дате отправления
От: Tom Lane
Дата:
От: Jelle Ruttenberg
Дата: