Re: [SQL] DEFAULT confusion
От | Moray McConnachie |
---|---|
Тема | Re: [SQL] DEFAULT confusion |
Дата | |
Msg-id | 003001bef9c9$e813b160$0102a8c0@public.ox.ac.uk обсуждение исходный текст |
Ответ на | DEFAULT confusion (Hroi Sigurdsson <hroi@ninja.dk>) |
Список | 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.
В списке pgsql-sql по дате отправления: