Typical foreign key creation question

From: Sean Davis <sdavis2(at)mail(dot)nih(dot)gov>
To: pgsql-novice(at)postgresql(dot)org
Subject: Typical foreign key creation question
Date: 2004-08-04 06:42:03
Message-ID: 65330CBA-E5E1-11D8-8690-000393CFE1C4@mail.nih.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I am migrating from mysql to postgresql. I have many auto_increment
columns, all requiring code during loading to explicitly save the last
insert id of one table to place into another linked table. I know that
I can probably do this with sequences and directly selecting current
value. However, I would like to learn to do this more simply in
postgresql using views/triggers. I have looked for a code example
showing the "canonical" linked table creation idiom in postgresql, but
have not found it. I have tables that look like:

CREATE TABLE abixref (
xrefid int,
platepos INT NOT NULL,
gene_id VARCHAR(30),
value VARCHAR(75),
dbid INT NOT NULL
);

CREATE TABLE abidb (
dbid INT NOT NULL,
db VARCHAR(30),
);

Of course, dbid is the foreign key with abidb referencing the column of
the same name in the other table.

Thanks,
Sean

Browse pgsql-novice by date

  From Date Subject
Next Message Oliver Fromme 2004-08-04 09:54:16 Re: Performance Bottleneck
Previous Message Kenneth Marshall 2004-08-03 18:38:55 Re: Performance Bottleneck