【问题标题】:Identify json type in postgresql在 postgresql 中识别 json 类型
【发布时间】:2021-12-02 04:26:34
【问题描述】:

是否有一个函数或方法可以轻松确定 postgresql 中的 json 数据类型?

例如:

select key, value, pg_typeof(value) FROM jsonb_each('{"foo":1,"bar":"2","ack":[1,2,3]}'::jsonb)

返回:

key value   pg_typeof
ack [1, 2, 3]   jsonb
bar "2" jsonb
foo 1   jsonb

如何确定 ack 的值是一个数组,bar 是一个字符串,而 foo 是一个数字?

【问题讨论】:

    标签: json postgresql jsonb postgresql-13


    【解决方案1】:

    从这里JSON operatorsjsonb_typeof

     select key, value, jsonb_typeof(value) FROM jsonb_each('{"foo":1,"bar":"2","ack":[1,2,3]}'::jsonb);
     key |   value   | jsonb_typeof 
    -----+-----------+--------------
     ack | [1, 2, 3] | array
     bar | "2"       | string
     foo | 1         | number
    

    【讨论】:

    • 现在我觉得自己很愚蠢。感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多