pg_dumpall and check constraints - Mailing list pgsql-general

From Guillaume Perréal
Subject pg_dumpall and check constraints
Date
Msg-id 395C536D.A3161C5F@lyon.cemagref.fr
Whole thread Raw
Responses Re: pg_dumpall and check constraints  (Philip Warner <pjw@rhyme.com.au>)
List pgsql-general
Hello.

Here is an extract from my database definition:

CREATE TABLE information (
    fieldName text NOT NULL CHECK (fieldName <> ''),
    code char NOT NULL CHECK (code <> ''),
    label  text,

    PRIMARY KEY (fieldName, code)
);

-- Filling the table "information"
COPY information FROM stdin;
station.type    H    hydrological
parameter.type    Q    discharge
...
\.

-- Function that checks a field value is in the table "information".
CREATE FUNCTION checkInfo(text, char) RETURNS bool AS
    'SELECT $2::char IN (SELECT code FROM information WHERE fieldName = $1::text)'
    LANGUAGE 'sql';

-- A table using checkInfo
CREATE TABLE station (
    code  text NOT NULL,
    type char NOT NULL,
    name   text,
    longitude text,
    latitude text,
    altitude float,

    PRIMARY KEY (code),

    CONSTRAINT stationCodeNotEmpty
    CHECK  (code <> ''),

    CONSTRAINT existingStationType
    CHECK  (verifierInfo('station.type', type))
);

As you can guess, the definition order is an important point.

But when I use pg_dumpall, it produces a script that don't respect the order. So I can't use this script to restore the database.

And the question is: Is there a better way to do what I want (checking field values from different tables against data in one table) that allow pg_dumpall to works ?

Thanks.

Guillaume Perréal - Stagiaire MIAG
Cemagref (URH), Lyon, France
Tél: (+33) 4.72.20.87.64
 

pgsql-general by date:

Previous
From: Lincoln Yeoh
Date:
Subject: Re: Leaving transactions open for long periods. Was: NOTICE messages during table drop
Next
From: Karel Zak
Date:
Subject: Re: Timezone template for to_char(timestamp, '...')?