From: | "Moray McConnachie" <moray(dot)mcconnachie(at)computing-services(dot)oxford(dot)ac(dot)uk> |
---|---|
To: | "Hroi Sigurdsson" <hroi(at)ninja(dot)dk>, <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: [SQL] DEFAULT confusion |
Date: | 1999-09-08 07:15:17 |
Message-ID: | 003001bef9c9$e813b160$0102a8c0@public.ox.ac.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
> Suppose i have the following sequence, table and index:
>
> CREATE SEQUENCE stuff_seq;
> CREATE TABLE stuff (
> id INTEGER DEFAULT NEXTVAL('stuff_seq') NOT NULL,
> name TEXT,
> number INTEGER
> );
> CREATE UNIQUE INDEX stuff_id ON tabel(id);
>
> Then to properly insert rows i have to
>
> INSERT INTO tabel VALUES (NEXTVAL('tabel_seq'), "sometext", 123);
>
> I can't just
> INSERT INTO tabel VALUES (NULL, "something", 123);
>
> Then what is the point of the DEFAULT clause? In other words: How do I
> get away with not specifying anything for id?
It's not ideal, but if you make the sequence the last field in the table,
e.g.
CREATE TABLE tabel (this int2,that text,id serial)
, then you can do a
INSERT INTO tabel VALUES (5,'whatever);
& that works. I would love to know if there is a 'proper' solution, though.
From | Date | Subject | |
---|---|---|---|
Next Message | Herouth Maoz | 1999-09-08 09:25:59 | Re: [SQL] DEFAULT confusion |
Previous Message | Rudolph, Michael | 1999-09-08 05:50:48 | Failed Regression Tests due to SQL-Errors |