Search Postgresql Archives

pg_dump and check-constraints

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

For instance, i have such a database:
(it is just a silly example)


test=# create function check_b() returns bool as $$ declare s int; begin select into s sum(i) from b; if s > 3 then return true; else return false; end if; end;$$ language plpgsql;                                                                                                                                                                                     
CREATE FUNCTION                                                                                                                                                                      
test=*# create table b (i int);
CREATE TABLE                   
test=*# insert into b values (5);
INSERT 0 1                       
test=*# create table a (i int check(check_b()));
CREATE TABLE                                    
test=*# insert into a values(10);
INSERT 0 1                       
test=*# commit;                  
COMMIT

Okay. Now i make a Dump (it is a own schema called foo, not a whole database).
The dump is called 'foo.sql'.
(pg_dump -n foo test > foo.sql)


Now i tried to restore the schema:

test=# set search_path=public;
SET
test=*# drop schema foo cascade;
NOTICE:  drop cascades to 3 other objects
DETAIL:  drop cascades to function foo.check_b()
drop cascades to table foo.b
drop cascades to table foo.a
DROP SCHEMA
test=*# commit;
COMMIT
test=# \i foo.sql
SET
SET
SET
SET
SET
SET
CREATE SCHEMA
ALTER SCHEMA
SET
CREATE FUNCTION
ALTER FUNCTION
SET
SET
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
psql:foo.sql:67: ERROR:  new row for relation "a" violates check constraint "a_check"
CONTEXT:  COPY a, line 1: "10"



I know, i can use pg_dump with -F c, and later i can create a listefile,
reorder the objects in this listfile and pg_restore -L to solve that
problem.

But maybe pg_dump should first create the table without the
check-constraint, fill all tables and create this check-constraint at
the end. (in the same manner as foreign-key constraints)


And yes, version ist 8.4.1



Regards, Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux