Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

299
Vistas
How to create a column that is filled automatically based on a sequence in Postgresql?

is there any way to create a column that is half serial? that is imagine that I have the following table:

create table item (
     item_number   varchar(10)    PRIMARYKEY,

)

but I want the column item_number to be like this: ITEM001,ITEM002,ITEM003 .... so I want the word ITEM then a kind of a sequence after it.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

use a sequence with a default value:

create sequence item_number_seq;

create table item 
(
  item_number varchar(10) primary key default 'ITEM'||to_char(nextval('item_number_seq'), '00000')
);

But storing the same constant value for all rows is pretty much useless. Just use a regular sequence and add that constant when you display those values. Or use a view to to do that.

over 4 years ago · Santiago Trujillo Denunciar

0

Do it at query time or at the presentation layer:

create table item (item_number serial primary key);

select 'ITEM' || to_char(item, '999')
from item
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda