Composed Key and autoincrement - Mailing list pgsql-novice

From fbn
Subject Composed Key and autoincrement
Date
Msg-id 45C76182.9070001@libero.it
Whole thread Raw
Responses Re: Composed Key and autoincrement
List pgsql-novice
Hello,
I want to create a table with a primary key composed of 2 auto increment
(serial) value.
I don't speak english very well so I'gonna write you an example to let
you understand what's
my problem. Hope someone can help me.

For example

CREATE TABLE foo(
    keypartone   serial not null,
    keyparttwo   serial not null,
    var1              integer not null,
    PRIMARY KEY( keypartone   , keyparttwo   )
    );

If I do this inserts

INSERT INTO foo ( var1 ) VALUES (  7 );
INSERT INTO foo ( var1 ) VALUES (  9 );
INSERT INTO foo ( keypartone, var1 ) VALUES (  1, 111 );
INSERT INTO foo ( keypartone, var1 ) VALUES (  2, 3  );

I get this table

| 1 | 1 | 7 |
| 2 | 2 | 9 |
| 1 | 3 | 111 |
| 2 | 4 | 3 |


There is a way to program the 2 sequences to have the following result
instead???

INSERT INTO foo ( var1 ) VALUES (  7 );
INSERT INTO foo ( var1 ) VALUES (  9 );
INSERT INTO foo ( keypartone, var1 ) VALUES (  1, 111 );
INSERT INTO foo ( keypartone, var1 ) VALUES (  2, 3  );

| 1 | 1 | 7 |
| 2 | 1 | 9 |
| 1 | 2 | 111 |
| 2 | 2 | 3 |

There is a  way to do this?

Thank you a lot
Taioli Fabiano


pgsql-novice by date:

Previous
From: chrisj
Date:
Subject: is there more documentation?
Next
From: "Jasbinder Singh Bali"
Date:
Subject: Re: Stored Procedure to return a result set