From: | Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il> |
---|---|
To: | Hroi Sigurdsson <hroi(at)ninja(dot)dk>, pgsql-sql(at)postgreSQL(dot)org |
Subject: | Re: [SQL] DEFAULT confusion |
Date: | 1999-09-08 09:25:59 |
Message-ID: | l03130300b3fbdacad26a@[147.233.159.109] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
At 04:39 +0200 on 08/09/1999, Hroi Sigurdsson wrote:
> INSERT INTO tabel VALUES (NEXTVAL('tabel_seq'), "sometext", 123);
>
> I can't just
> INSERT INTO tabel VALUES (NULL, "something", 123);
<RANT MODE="old teacher">
[tearing hair off in despair]
Children, how many times do I have to tell you that...
</RANT>
In an insert statement, you should always mention the names of the fields
to which you enter values. The syntax should be:
INSERT INTO table (field1, field2, field3)
VALUES (value1, value2, value3);
The SQL syntax allows you to drop the field names when you insert to *all*
of them. But this is NOT recommended, and should be used only in ad-hoc
insert statement done, say, in psql when you just have something to fix on
the fly.
In REAL applications, always mention the fields. This will prevent mixups
due to changes in the schema over time by giving you clear error messages
such as 'column not found' etc., instead of finding obscure data conversion
errors or none at all.
Now, what's the relevance of this lecture to your question?
If you don't mention the name of a field, and that field has a default
value, the default value will be used. It's that simple!
INSERT INTO stuff (name, number)
VALUES ("sometext", 123);
Will do the trick.
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma
From | Date | Subject | |
---|---|---|---|
Next Message | Hroi Sigurdsson | 1999-09-08 12:43:52 | Re: [SQL] DEFAULT confusion |
Previous Message | Moray McConnachie | 1999-09-08 07:15:17 | Re: [SQL] DEFAULT confusion |