auto increment within a compound key

From: "Bogdoll, Dieter" <dieter(dot)bogdoll(at)siemens(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: auto increment within a compound key
Date: 2006-01-17 15:33:46
Message-ID: 5D0D32692F13134BB9C50F968727C4DDB1AEF1@MCHP7IEA.ww002.siemens.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I want to create a compound primary key. The elements of this primary
key should be
the fields called nb (int) and d (double). nb should be default and
autoincremented,
so that the following four inserts

insert into mytable (ts) values ( 1.0 )
insert into mytable (ts) values ( 1.1 )
insert into mytable (ts) values ( 1.1 )
insert into mytable (ts) values ( 2.0 )

delieveres me the following table content:

nb ts
----------------------------------
1 1.0
1 1.1
2 1.1
1 2.0

In MySQL the create table statement would look like:

CREATE TABLE mytable (
nb INT NOT NULL AUTO_INCREMENT,
timeStamp DOUBLE NOT NULL,
PRIMARY KEY (timeStamp, id)
)

Postgres gives me (using serial as replacement for AUTO_INCREMENT):

nb ts
----------------------------------
1 1.0
2 1.1
3 1.1
4 2.0

Is there any way to achieve the same result in Postgresql as the MySQL
AUTO_INCREMENT does?

Thanks.

Yours
Dieter

Responses

Browse pgsql-general by date

  From Date Subject
Next Message MG 2006-01-17 15:43:36 LIMIT + OFFSET
Previous Message Tom Lane 2006-01-17 15:30:59 Re: Strange error while executing query from front end: