简体   繁体   中英

Set nextval sequence data type to integer only

I have an issues running around my mind regarding default for 'id' field in my postgresql database. Here is the syntax:-

nextval('unsub_keyword_id_seq'::regclass)

However I'm not really understands even after read the documentations & I would like to set the value only for integer(digit only). I try to alter the column by change regclass to other OIDs but each time it will return errors.

Really appreciate if can get this solved very soon.

Update:

It just come to my idea on the data type for the column after I try & error with the code that will produce the id for the column. Is integer(postgresql in this case) have it's own default length or not? If I need to to insert long id, should I set the column length? Kindly advise.

sorry if my questions quite confusing. your comments may help me to improve it.

From the comments:

I need to insert an id with length of 50 with consist of 2 alphabets & the rest is numeric. the problems occur as the data type is in integer & the data inserting in unsuccessful. is it possible to insert my desired data by retain the data type to integer?

If I understand this correctly, you probably need to format a string, eg

format('%s%s', 'XX', nextval('some_sequence_name'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM