Search Postgresql Archives

auto increment within a compound key

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Title: auto increment within a compound key

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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux