pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Herouth Maoz <herouth@oumail.openu.ac.il>
To: Hroi Sigurdsson <hroi@ninja.dk>
To: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] DEFAULT confusion
Date: Wed, 8 Sep 1999 11:25:59 +0200
Message-ID: <l03130300b3fbdacad26a@[147.233.159.109]> (raw)
In-Reply-To: <37D5CC72.9A7CBD49@ninja.dk>

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





view thread (9+ messages)  latest in thread

Message-ID: <l03130300b3fbdacad26a@[147.233.159.109]>
Permalink:  ../l03130300b3fbdacad26a@%5B147.233.159.109%5D/
Also on:    postgresql.org/message-id/l03130300b3fbdacad26a@[147.233.159.109]

 · 

reply

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: herouth@oumail.openu.ac.il, hroi@ninja.dk
  Subject: Re: [SQL] DEFAULT confusion
  In-Reply-To: <l03130300b3fbdacad26a@[147.233.159.109]>
  References: <37D5CC72.9A7CBD49@ninja.dk> <l03130300b3fbdacad26a@[147.233.159.109]>

* 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