6
I have the following table in the database Postgres:
CREATE TABLE customer
(
userid character varying(30) NOT NULL,
firstname character varying(30) NOT NULL,
lastname character varying(30) NOT NULL,
balance double precision NOT NULL,
PRIMARY KEY (userid)
)
It would be possible to create a sequence of the auto increment type but one of the type VARCHAR
?
'Cause I got an object of business rule that needs a guy String
.
I know the procedure for creating a sequence with the type serial
:
CREATE TABLE customer
(
userid serial NOT NULL,
...
...
...
PRIMARY KEY (userid)
)
But like I said before, I need a guy VARCHAR
, because the values that will be entered as the primary key will have this form:
id001
id002
id003
@That I know!! But I want to create a varchar type value that is high increment!!
– Pena Pintada
Wait I will change my answer with an example.
– Eduardo Binotto
@Eduardobrito I still thought about using a procedure to do this but I dismissed the idea, however, with a Tigger , as I could do this?
– Pena Pintada
I changed the answer, take a look if it can help you.
– Eduardo Binotto
If you solve your problem and want to of course give me the best answer I thank you.
– Eduardo Binotto
@Eduardobrito This Generator seq_name I must create in what way?
– Pena Pintada
Let’s go continue this discussion in chat.
– Pena Pintada
CREATE SEQUENCE seq_name START 1;
– Eduardo Binotto