将 nextval 序列数据类型设置为仅整数
Set nextval sequence data type to integer only
关于我的 postgresql 数据库中 'id' 字段的默认设置,我有一个问题 运行。语法如下:-
nextval('unsub_keyword_id_seq'::regclass)
然而,即使在阅读 documentations 之后我也不是很理解,我只想为整数(仅限数字)设置值。我尝试通过将 regclass 更改为其他 OID 来更改列,但每次都会 return 错误。
非常感谢能尽快解决这个问题。
更新:
在我尝试使用将为该列生成 ID 的代码并出错后,我才想到该列的数据类型。
整数(在本例中为 postgresql)是否有自己的默认长度?
如果我需要插入长id,我应该设置列长度吗?
请指教。
抱歉,如果我的问题很混乱。您的意见可能会帮助我改进它。
来自评论:
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?
如果我理解正确,您可能需要格式化字符串,例如
format('%s%s', 'XX', nextval('some_sequence_name'))
关于我的 postgresql 数据库中 'id' 字段的默认设置,我有一个问题 运行。语法如下:-
nextval('unsub_keyword_id_seq'::regclass)
然而,即使在阅读 documentations 之后我也不是很理解,我只想为整数(仅限数字)设置值。我尝试通过将 regclass 更改为其他 OID 来更改列,但每次都会 return 错误。
非常感谢能尽快解决这个问题。
更新:
在我尝试使用将为该列生成 ID 的代码并出错后,我才想到该列的数据类型。 整数(在本例中为 postgresql)是否有自己的默认长度? 如果我需要插入长id,我应该设置列长度吗? 请指教。
抱歉,如果我的问题很混乱。您的意见可能会帮助我改进它。
来自评论:
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?
如果我理解正确,您可能需要格式化字符串,例如
format('%s%s', 'XX', nextval('some_sequence_name'))