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.
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.
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