【问题标题】:Is there a way to express a Postgres literal int in hexadecimal?有没有办法用十六进制表示 Postgres 文字 int?
【发布时间】:2010-09-29 16:53:14
【问题描述】:

我有一个很大的十六进制数字列表,我想插入到 PostgresQL 表中。我尝试过这样的事情:

INSERT INTO foo (i)
VALUES (0x1234);

...但这没有用。这可能吗?

【问题讨论】:

    标签: sql postgresql


    【解决方案1】:

    正如您所指出的,您可以以十六进制编写的bit-string constant 开头,然后将type-cast it 转换为您想要的类型。所以,

    INSERT INTO foo (i) VALUES (CAST(x'1234' AS int))
    

    INSERT INTO foo (i) VALUES (x'1234'::int) -- postgres-specific syntax
    

    【讨论】:

      【解决方案2】:

      这似乎有效:

       CAST(X'3e000000' AS INT)
      

      【讨论】:

        【解决方案3】:

        你可以使用

        x'1234'::int;
        

        更多信息请看我的帖子,

        【讨论】:

          猜你喜欢
          • 2016-11-12
          • 2018-01-19
          • 2015-04-01
          • 1970-01-01
          • 1970-01-01
          • 2022-01-11
          • 1970-01-01
          • 1970-01-01
          • 2020-01-19
          相关资源
          最近更新 更多