Обсуждение: import and foreign keys
i'm in the process of importing my data from my existing db (mysql) to pgsql. one thing i'm confused about is the use of foreign keys. in my existing db, i use the foreign keys to relate from one table to the next. it's a forum type application. the key is based on an auto-increment field. in the past when i've dumped my data from mysql and re-import it back into mysql it figured out that the foreign keys (auto-increment) are just what they are and do the proper things so that those auto-increment field keep on incrementing from the last highest number. i'm wondering what will happen to that field if i import into pgsql? will pgsql figure out what the last highest id is and continue from there? assuming i've defined my table structures properly using: CREATE SEQUENCE "next_url_id" start 1 increment 1 maxvalue 2147483647 CREATE TABLE "url" ( "rec_id" integer DEFAULT nextval('next_url_id'::text) NOT NULL, ... the reason i'm hesitant is because i've been reading the mailing list on this subject and i'm confused. there were some talks about how i'd lose my relations between tables because the foreign keys would be lost during import. i think this was on the thread about OID etc.
If you build your strucutres as you've shown (explicitely creating your sequences), and then import, you shouldn't have any problem, with one caveat. You'll need to determine the hightest current key for each table and start your sequence accordingly. To start a squence at 500: > CREATE SEQUENCE "next_url_id" start 500 increment 1 maxvalue 2147483647 "Thomas T. Thai" wrote: > > i'm in the process of importing my data from my existing db (mysql) to > pgsql. one thing i'm confused about is the use of foreign keys. in my > existing db, i use the foreign keys to relate from one table to the > next. it's a forum type application. the key is based on an auto-increment > field. > ... > i'm wondering what will happen to that field if i import into pgsql? will > pgsql figure out what the last highest id is and continue from > there? assuming i've defined my table structures properly using: > > CREATE SEQUENCE "next_url_id" start 1 increment 1 maxvalue 2147483647 > > CREATE TABLE "url" ( > "rec_id" integer DEFAULT nextval('next_url_id'::text) NOT NULL, > ... -- Richard Seymour : Anarchy Software, Inc. - * - - * - - - * -+- * - - - * - - * - `°º¤ø,¸ ¸,ø¤º°' `°º¤ø,¸¸,ø¤º°