Re: A couple of newbie questions ...

From: "Albe Laurenz" <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "admin *EXTERN*" <mick(at)mjhall(dot)org>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: A couple of newbie questions ...
Date: 2008-07-23 13:19:26
Message-ID: D960CB61B694CF459DCFB4B0128514C20256FE98@exadv11.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

admin wrote:
> So anyway, life story aside, I have a couple of very newbie questions
> after tinkering with PostgreSQL 8.1.9 for a day converting some
> PHP/MySQL code:

Here I have to ask the obvious thing: Why not a more current version?

> 1. Is a SEQUENCE what I use instead of auto_increment?

Yes. Even better, you can use the pseudo-type "serial" and "bigserial"
which is in reality "integer" and "bigint" with nextval(...) in DEFAULT.
The advantage over an explicitly created sequence is that with "serial",
the sequence will be dropped automatically if the table is dropped.

Consult the documentation for details!

> 2. Does this work in PostgreSQL:
>
> INSERT INTO table VALUES ('x','y','z')
>
> or do I need to do this
>
> INSERT INTO table (fld_x,fld_y,fld_z) VALUES ('x','y','z')

The first will work as specified by the SQL standard.

> 3. Does this work in PostgreSQL:
>
> INSERT INTO table VALUES ('','y','z')
>
> where the empty first item is intended for an auto_increment/SEQUENCE id
> field?
> If not, what is an alternative?

No, this won't work.

Use:

INSERT INTO table (fld_y, fld_z) VALUES ('y','z')

Yours,
Laurenz Albe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2008-07-23 14:43:23 Re: A couple of newbie questions ...
Previous Message Guillaume Bog 2008-07-23 13:16:37 Re: High activity short table and locks