Re: Entering data in serial column

From: david(at)netventures(dot)com(dot)au
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Entering data in serial column
Date: 2001-09-29 13:59:21
Message-ID: Pine.LNX.4.21.0109292346380.5363-100000@rapt.netventures.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi There,

If you omit the column names, the values are assumed to follow the order
of the column names in the table definition. So if you have the columns
with default values at the end of the table definition, then you don't
need to insert a value for them. Same as in C.

It is better practice though to name the columns, as then if you rebuild
your schema, or alter the table (Effecting the order of the columns) then
the insert statement retains its meaning.

If you have 40 columns, then you are going to have an awfull lot of
trouble maintaining the insert statement anyway. Whats an extra few lines
of SQL with the column names (they will probably help you keep track of
which one you are up to anyway).

Devrim GUNDUZ <devrim(at)oper(dot)metu(dot)edu(dot)tr> Wrote:
> Now, since id is a serial, while inserting data into info I write:
>
> INSERT INTO info (name,surname,address) VALUES ('$name','$surname',
> '#address');
>
> Is there a shorter way of doing this? I mean, if I had 40 fields in this
> table, would I have to write all the fields? I mean, is there a syntax
> beginning like
>
> INSERT INTO info VALUES (....

--
David Stanaway

Browse pgsql-sql by date

  From Date Subject
Next Message Pat M 2001-09-29 16:17:28 Function return rows?
Previous Message Devrim GUNDUZ 2001-09-29 10:23:58 Entering data in serial column