From: Moray McConnachie <moray.mcconnachie@computing-services.oxford.ac.uk>
To: Hroi Sigurdsson <hroi@ninja.dk>
To: pgsql-sql@postgresql.org
Subject: Re: [SQL] DEFAULT confusion
Date: Wed, 8 Sep 1999 08:15:17 +0100
Message-ID: <003001bef9c9$e813b160$0102a8c0@public.ox.ac.uk> (raw)
References: <37D5CC72.9A7CBD49@ninja.dk>
> 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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: moray.mcconnachie@computing-services.oxford.ac.uk, hroi@ninja.dk
Subject: Re: [SQL] DEFAULT confusion
In-Reply-To: <003001bef9c9$e813b160$0102a8c0@public.ox.ac.uk>
References: <37D5CC72.9A7CBD49@ninja.dk> <003001bef9c9$e813b160$0102a8c0@public.ox.ac.uk>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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