如何在postgresql中将bigint中的字段更改为字符?

dan*_*car 4 postgresql

我收到错误"不兼容的类型:bigint和字符变化." 但我知道通常有一个技巧可以绕过这个.

Den*_*rdy 9

似乎在PG 9.0中工作正常,但如果不在您的版本中,您可以始终先转换为文本:

select 1::bigint::text::varchar;
Run Code Online (Sandbox Code Playgroud)


Sco*_*owe 7

alter table abc alter column def type varchar using def::varchar;
Run Code Online (Sandbox Code Playgroud)