From: | Hroi Sigurdsson <hroi(at)ninja(dot)dk> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | DEFAULT confusion |
Date: | 1999-09-08 02:39:46 |
Message-ID: | 37D5CC72.9A7CBD49@ninja.dk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hello postgresql'ers (how do you pronounce that?).
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? And how (if
possible/recommendable) do I force the id value to be nothing but
NEXTVAL('stuff_seq'), ie. not just an arbitrary number?
In short I want to emulate MySQL's way of doing
CREATE TABLE(
id INT NOT NULL AUTO_INCREMENT,
name TEXT,
int INT,
UNIQUE(id)
);
I hope I made myself sufficiently clear.
Thank you for your time.
PS.
Where can I get more information about the REFERENCES keyword and when
will it be fully working in Postgres?
PPS.
Are there any books out there that cover Postgresql?
--
Hroi Sigurdsson
hroi(at)ninja(dot)dk
From | Date | Subject | |
---|---|---|---|
Next Message | Rudolph, Michael | 1999-09-08 05:50:48 | Failed Regression Tests due to SQL-Errors |
Previous Message | Hroi Sigurdsson | 1999-09-07 23:28:04 | DEFAULT confusion |