如何使用雪花 object_construct() 函数而不是按键排序来维护元素的顺序?

Sam*_*mir 3 json object-construction snowflake-cloud-data-platform

以下雪花查询返回 JSON 结构,但输出按键排序。如何不按键排序但保留顺序?是否有什么参数需要设置?

select
object_construct
(
  'entity',  'XYZ',
  'allowed',  'Yes',
  'currency', 'USD',
  'statement_month','July, 2020'
 )
Run Code Online (Sandbox Code Playgroud)

输出:--按键排序

{
  "allowed": "Yes",
  "currency": "USD",
  "entity": "XYZ",
  "statement_month": "July, 2020"
}
Run Code Online (Sandbox Code Playgroud)

预期输出:--与指定的顺序相同

{
  "entity": "XYZ",
  "allowed": "Yes",
  "currency": "USD",
  "statement_month": "July, 2020"
}
Run Code Online (Sandbox Code Playgroud)

Raj*_*Deb 5

JSON 是名称和值的无序集合。JSON 无法保证顺序。

构造的对象不一定保留键值对的原始顺序。

你可以像下面这样做

SELECT mytable:entity::string as entity,
mytable:allowed::string as allowed,
mytable:currency::string as currency,
mytable:statement_month::string as statement_month
from
(select
object_construct
(
  'entity',  'XYZ',
  'allowed',  'Yes',
  'currency', 'USD',
  'statement_month','July, 2020'
 ) mytable);
Run Code Online (Sandbox Code Playgroud)