Composed Key and autoincrement

Поиск
Список
Период
Сортировка
От fbn
Тема Composed Key and autoincrement
Дата
Msg-id 45C76182.9070001@libero.it
обсуждение исходный текст
Ответы Re: Composed Key and autoincrement  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: chrisj
Дата:
Сообщение: is there more documentation?
Следующее
От: "Jasbinder Singh Bali"
Дата:
Сообщение: Re: Stored Procedure to return a result set