Bug #787: Backup Files Output Constraints Before Functions

From: pgsql-bugs(at)postgresql(dot)org
To: pgsql-bugs(at)postgresql(dot)org
Subject: Bug #787: Backup Files Output Constraints Before Functions
Date: 2002-09-27 20:52:21
Message-ID: 20020927205221.CA95F4760EC@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

David Wheeler (david(at)wheeler(dot)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 constraint references 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 tests on 7.3b1.

Thanks!

David

Sample Code

No file was uploaded with this report

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Adam Doligalski 2002-09-27 20:53:12 Nie ma mnie w biurze
Previous Message Tom Lane 2002-09-27 19:55:50 Re: Bug #786: simbols in relation names