检查 json 属性 的类型
Checking the type of a json property
我正在寻找一种方法来验证 PostgreSQL 中 json 变量的类型。
这就是我的意思:
get_type('"s"'::josn) => 'string'
get_type('1'::json) => 'number'
get_type('2.3'::json) => 'number'
get_type('null'::json) => 'null'
get_type('[]'::json) => 'array'
get_type('{}'::json) => 'object'
我正在寻找 get_type
函数。
您可以使用 json_typeof
(或 jsonb_typeof
用于 9.4 的 jsonb
)。尽管 missing from the 9.3 documentation it's apparently present, and is documented in the manual for json functions in 9.4 and above.
我正在寻找一种方法来验证 PostgreSQL 中 json 变量的类型。 这就是我的意思:
get_type('"s"'::josn) => 'string'
get_type('1'::json) => 'number'
get_type('2.3'::json) => 'number'
get_type('null'::json) => 'null'
get_type('[]'::json) => 'array'
get_type('{}'::json) => 'object'
我正在寻找 get_type
函数。
您可以使用 json_typeof
(或 jsonb_typeof
用于 9.4 的 jsonb
)。尽管 missing from the 9.3 documentation it's apparently present, and is documented in the manual for json functions in 9.4 and above.