pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
Foreign key pg_dump issue and serial column type 2+ messages / 2 participants [nested] [flat]
* Foreign key pg_dump issue and serial column type @ 2005-06-30 00:25 Vsevolod (Simon) Ilyushchenko <simonf@cshl.edu> 2005-06-30 01:15 ` Re: Foreign key pg_dump issue and serial column type Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 1 reply; 2+ messages in thread From: Vsevolod (Simon) Ilyushchenko @ 2005-06-30 00:25 UTC (permalink / raw) To: pgsql-sql Hi, As a relative newbie to postgres, I've run into to weirdisms that I don't quite know how to handle: 1. I have a many-to-many table 'people_roles' containing fields 'person_code' and 'role_code'. It links tables 'people' and 'roles'. There are foreign key constraints: ALTER TABLE PEOPLE_ROLES add CONSTRAINT PRO_PEE_FK FOREIGN KEY(PERSON_CODE) REFERENCES PEOPLE(PERSON_CODE) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE; ALTER TABLE PEOPLE_ROLES add CONSTRAINT PRO_ROE_FK FOREIGN KEY(ROLE_CODE) REFERENCES ROLES(ROLE_CODE) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE; However, when I pg_dump the database and import it on another server, the tables are exported alphabetically, so when the 'people_roles' table is created with its foreign keys, the table 'roles' does not exist yet. Thus, the foreign key creation fails. Is there a way around it? 2. I've just discovered the 'serial' column type and tried to do this: alter table people_roles alter column people_roles_code type serial; To my surprise, it fails: ERROR: type "serial" does not exist However, I can create new tables with the 'serial' type without a hitch. Is it a bug or a feature? I'm running postgres 8.0.3 on Fedora Core 4. Thanks, Simon -- Simon (Vsevolod ILyushchenko) simonf@cshl.edu http://www.simonf.com Terrorism is a tactic and so to declare war on terrorism is equivalent to Roosevelt's declaring war on blitzkrieg. Zbigniew Brzezinski, U.S. national security advisor, 1977-81 ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Foreign key pg_dump issue and serial column type 2005-06-30 00:25 Foreign key pg_dump issue and serial column type Vsevolod (Simon) Ilyushchenko <simonf@cshl.edu> @ 2005-06-30 01:15 ` Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 2+ messages in thread From: Tom Lane @ 2005-06-30 01:15 UTC (permalink / raw) To: Vsevolod (Simon) Ilyushchenko <simonf@cshl.edu>; +Cc: pgsql-sql "Vsevolod (Simon) Ilyushchenko" <simonf@cshl.edu> writes: > However, when I pg_dump the database and import it on another server, > the tables are exported alphabetically, so when the 'people_roles' table > is created with its foreign keys, the table 'roles' does not exist yet. > Thus, the foreign key creation fails. Is there a way around it? Are you sure you are using 8.0 pg_dump? That's a longstanding deficiency in older versions, but 8.0 is not supposed to have a problem with it. If you're sure it's an up-to-date pg_dump, could you provide a complete test case (ie, a script to create a database that pg_dump has trouble with)? > 2. I've just discovered the 'serial' column type and tried to do this: > alter table people_roles alter column people_roles_code type serial; > To my surprise, it fails: > ERROR: type "serial" does not exist Serial isn't quite a true type, and so it doesn't work in every context that you might think. It'd probably make sense for "alter column type" to accept it, but for now what you gotta do is create a sequence and set the column default manually. regards, tom lane ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2005-06-30 01:15 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2005-06-30 00:25 Foreign key pg_dump issue and serial column type Vsevolod (Simon) Ilyushchenko <simonf@cshl.edu> 2005-06-30 01:15 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox