Skip to content

Support OBJECT_KEYS Snowflake to DuckDB #6660

@kyle-cheung

Description

@kyle-cheung

There is currently no transpilation for OBJECT_KEYS reading from Snowflake and writing DuckDB.

Reproducible Code

import sqlglot

sql = """
SELECT OBJECT_KEYS(test)
FROM test_data
"""
sqlglot.transpile(sql, "snowflake", "duckdb", pretty=True)[0]
>>
SELECT
  OBJECT_KEYS(test)
FROM test_data

In Snowflake:

CREATE OR REPLACE TEMPORARY TABLE test_data AS 
SELECT PARSE_JSON('{"is_active": false, "cheese_count" : 5}') AS test;

SELECT OBJECT_KEYS(test)
FROM test_data;

┌──────────────────────┐
│  object_keys(test)   │
├──────────────────────┤
│ [is_active, is_true] │
└──────────────────────┘

Describe the solution you'd like
This should transpile to JSON_KEYS

SELECT json_keys(test) 
FROM test_data;

Describe alternatives you've considered
n/a

Additional context
Snowflake docs https://docs.snowflake.com/en/sql-reference/functions/object_keys
DuckDB docs https://duckdb.org/docs/stable/data/json/json_functions#json-scalar-functions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions