Skip site navigation (1) Skip section navigation (2)

Re: inserting values like in mySQL

From: "Giorgio A(dot)" <jh(at)libero(dot)it>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Re: inserting values like in mySQL
Date: 2001-05-22 18:10:13
Message-ID: 002b01c0e2ea$728f6a40$2f50fea9@pollicino (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
i'll answer only to a part of your question, since i'm not sure of the other

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(dot)Asemann(at)rrze(dot)uni-erlangen(dot)de>
To: <pgsql-novice(at)postgresql(dot)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(at)rrze(dot)uni-erlangen(dot)de
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?

In response to

pgsql-novice by date

Next:From: David LealDate: 2001-05-22 18:21:08
Subject: postgreSQL 7.0.3 + kdevelop 1.4.1
Previous:From: leeDate: 2001-05-22 16:13:04
Subject: postmaster

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group