postgresql 有没有办法用十六进制表示 Postgres 文字 int?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/414664/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a way to express a Postgres literal int in hexadecimal?
提问by mike
I have a big list of hexadecimal numbers I'd like to insert into a PostgresQL table. I tried something like this:
我有一个很大的十六进制数字列表,我想插入到 PostgresQL 表中。我试过这样的事情:
INSERT INTO foo (i)
VALUES (0x1234);
...but that didn't work. Is this possible?
……但这没有用。这可能吗?
回答by Rob Kennedy
As you've noted, you can start with a bit-string constantwritten in hexadecimal, and then type-cast itto the type you want. So,
正如您所指出的,您可以从一个以十六进制编写的位串常量开始,然后将其强制转换为您想要的类型。所以,
INSERT INTO foo (i) VALUES (CAST(x'1234' AS int))
or
或者
INSERT INTO foo (i) VALUES (x'1234'::int) -- postgres-specific syntax
回答by mike
This seems to work:
这似乎有效:
CAST(X'3e000000' AS INT)
回答by Evan Carroll
You can just use
你可以使用
x'1234'::int;
For more information see my post on,
有关更多信息,请参阅我的帖子,