Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

295
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda