Re: inserting values like in mySQL - Mailing list pgsql-novice

From Giorgio A.
Subject Re: inserting values like in mySQL
Date
Msg-id 002b01c0e2ea$728f6a40$2f50fea9@pollicino
Whole thread Raw
In response to inserting values like in mySQL  (Peter Asemann <Peter.Asemann@rrze.uni-erlangen.de>)
List pgsql-novice
i'll answer only to a part of your question, since i'm not sure of the other
part:

you can create a SEQUENCE with something like:

CREATE SEQUENCE "name_of_the_seq" start 1 increment 1 maxvalue 2147483647
minvalue 1  cache 1

and then add a column like:

"column_name" int4 DEFAULT nextval('name_of_the_seq'::text) NOT NULL

this column will be auto-incrementing, so when you do a INSERT you won't
have to pass any parameter for to this column.

hope this helped you,
Giorgio A.


----- Original Message -----
From: "Peter Asemann" <Peter.Asemann@rrze.uni-erlangen.de>
To: <pgsql-novice@postgresql.org>
Sent: Friday, May 18, 2001 6:03 PM
Subject: [NOVICE] inserting values like in mySQL


> Hi there!
>
> We (me and others from my group)  have to convert mySQL syntax to
> PostGreSQL, and incidentally we had some problems.
>
> We have a table named users with ID, name, pass as columns.
>
> In mySQL we had the column "ID" set to auto-increment. It took us some
> time to find out how to use the "serial" feature ;-)
>
> In mySQL it was like this:
>
> insert into users values ('','peter','my_pass');
>
> In PostGreSQL this does not work. The only thing that works is
>
> insert into users (name,pass) values ('peter','my_pass');
>
> Apparently this is longer, and we'll have tables with much more columns,
> so we'll have to write much more than in mySQL, and as we're lazy people
> (all programmers are, Larry Wall says), we don't want to write a single
> character more than necessary.
>
> Is there a way to set all columns without explicitly giving their
> names? Isn't there something to indicate that the value we give to the
> database is only a dummy like the '' in mySQL?
>
> Hope you got the point... maybe this question is really stupid and I
> managed to overlook the hints written in 20-pixels height on page one of
> the "PostGreSQL manual for complete morons" dealing with this problem ;-)
>
> Thanks for reading,
>
> ---------------------------------------------------------
> Peter Asemann                 unrzb8@rrze.uni-erlangen.de
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl


pgsql-novice by date:

Previous
From: David Leal
Date:
Subject: postgreSQL 7.0.3 + kdevelop 1.4.1
Next
From: Nabil Sayegh
Date:
Subject: Re: inserting values like in mySQL