Re: Problems w. SERIAL

From: Joel Burton <jburton(at)scw(dot)org>
To: Morten Primdahl <morten(at)primdahl(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Problems w. SERIAL
Date: 2001-05-07 17:46:38
Message-ID: Pine.LNX.4.21.0105071343500.21997-100000@olympus.scw.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, 5 May 2001, Morten Primdahl wrote:

> CREATE TABLE tbl_a (id SERIAL PRIMARY KEY, data VARCHAR(5));
> CREATE TABLE tbl_b (id SERIAL PRIMARY KEY, data VARCHAR(5));
>
> CREATE TABLE tbl_c
> (id SERIAL PRIMARY KEY,
> data VARCHAR(50),
> a SERIAL CONSTRAINT a_ref REFERENCES tbl_a(id),
> b SERIAL CONSTRAINT b_ref REFERENCES tbl_b(id)
> );
>
> INSERT INTO tbl_c (data, a, b) VALUES ('c data',1,1);
>
> I get ERROR: Relation 'tbl_c_id_seq' does not exist
> even though that sequence was implicitly created upon
> creation of tbl_c - or?

re: structure of table C, I think you're misunderstand something
about SERIALs. A SERIAL is just another name for an int that automatically
has a sequence set up for it. So, if in table C, you want to store
references to tables a and b, you want you schema to be:

CREATE TABLE tbl_c (
id serial primary key,
a int references tbl_a,
b int references tbl_b
);

note the use of INTs, not SERIALs.

I don't know if that will explain the weirdness of your error message,
but, even if not, it will certainly a future error! :-)

HTH,
--
Joel Burton <jburton(at)scw(dot)org>
Director of Information Systems, Support Center of Washington

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joel Burton 2001-05-07 18:03:06 Re: PostgreSQL vs. Interbase
Previous Message Rosa Maria Carro Salas 2001-05-07 17:24:30 Re: RecordSets, getString and charSets