Bug #787: Backup Files Output Constraints Before Functions - Mailing list pgsql-bugs

From pgsql-bugs@postgresql.org
Subject Bug #787: Backup Files Output Constraints Before Functions
Date
Msg-id 20020927205221.CA95F4760EC@postgresql.org
Whole thread Raw
Responses Nie ma mnie w biurze  (Adam Doligalski <drsky@atm.com.pl>)
Re: Bug #787: Backup Files Output Constraints Before Functions  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
David Wheeler (david@wheeler.net) reports a bug with a severity of 2
The lower the number the more severe it is.

Short Description
Backup Files Output Constraints Before Functions

Long Description
Bricolage has a table with a constraint that uses a custom function. The code to build it is functionally equivalent to
this:

CREATE TABLE "testing" (
    first varchar(32),
    try_me numeric(1,0)
);

CREATE   FUNCTION try_it()
         RETURNS BOOLEAN
AS       'SELECT TRUE'
LANGUAGE 'sql'
WITH     (isstrict);

ALTER TABLE testing ADD CONSTRAINT ck_testing
  CHECK (try_it());


When backing up, however, this call to pg_dump:

% pg_dump -U postgres -Oxd testing > test-backup.sql

Outputs this:

--
-- PostgreSQL database dump
--

SET search_path = public, pg_catalog;

--
-- TOC entry 2 (OID 517307)
-- Name: testing; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE testing (
    first character varying(32),
    try_me numeric(1,0),
    CONSTRAINT ck_testing CHECK (try_it())
);


--
-- TOC entry 3 (OID 517309)
-- Name: try_it (); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION try_it () RETURNS boolean
    AS 'SELECT TRUE'
    LANGUAGE sql STRICT;


--
-- Data for TOC entry 4 (OID 517307)
-- Name: testing; Type: TABLE DATA; Schema: public; Owner: postgres
--

Any attempt to restore this database will unfortunately fail. The testing table won't exist because the ck_testing
constraintreferences the try_it() function, which of course doesn't exist yet: 

% psql -U postgres testing < ~/Desktop/test-backup.sql
SET
ERROR:  Function try_it() does not exist
        Unable to identify a function that satisfies the given argument types
        You may need to add explicit typecasts
CREATE FUNCTION

Would it be possible for pg_dump to do the right thing here? This issue exists with 7.1 and later. I just ran the above
testson 7.3b1. 

Thanks!

David

Sample Code


No file was uploaded with this report

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: Bug #786: simbols in relation names
Next
From: Adam Doligalski
Date:
Subject: Nie ma mnie w biurze