auto increment within a compound key

Поиск
Список
Период
Сортировка
От Bogdoll, Dieter
Тема auto increment within a compound key
Дата
Msg-id 5D0D32692F13134BB9C50F968727C4DDB1AEF1@MCHP7IEA.ww002.siemens.net
обсуждение исходный текст
Ответы Re: auto increment within a compound key  (Michael Fuhr <mike@fuhr.org>)
Список 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

В списке pgsql-general по дате отправления:

Предыдущее
От: "Nik"
Дата:
Сообщение: Permission denied on relation
Следующее
От: "Silas Justiniano"
Дата:
Сообщение: Replicating a remote database (backuping)