PostgreSQL - Consecutivo en postgresql

 
Vista:

Consecutivo en postgresql

Publicado por jorge anibal escobar (7 intervenciones) el 23/10/2002 15:39:46
tengo una tabla y necesito crear un campo que se auto incremente un consecutivo como le hago mil gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Consecutivo en postgresql

Publicado por jorge anibal escobar (7 intervenciones) el 23/10/2002 16:44:54
se hace con la secuencia CREATE SEQUENCE

Create an ascending sequence called serial, starting at 101:

CREATE SEQUENCE serial START 101;

Select the next number from this sequence

SELECT NEXTVAL ('serial');

nextval
-------
114


Use this sequence in an INSERT:

INSERT INTO distributors VALUES (NEXTVAL('serial'),'nothing');

Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar