Re: A couple of newbie questions ... - Mailing list pgsql-general

From Albe Laurenz
Subject Re: A couple of newbie questions ...
Date
Msg-id D960CB61B694CF459DCFB4B0128514C20256FE98@exadv11.host.magwien.gv.at
Whole thread Raw
In response to A couple of newbie questions ...  (admin <mick@mjhall.org>)
List 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

pgsql-general by date:

Previous
From: "Guillaume Bog"
Date:
Subject: Re: High activity short table and locks
Next
From: "Scott Marlowe"
Date:
Subject: Re: A couple of newbie questions ...