Skip to content
Advertisement

Joining two JSON objects in Snowflake

What’s up,

I have two JSON objects, generated from the same Snowflake table (Table 1 here). I want to join/merge them on their “_id” field, in order to produce this nested json kind of structure.

  1. How can I do this? I tried aliasing them and using SELECT * from dc JOIN rs ON rs.:_id = dc:_id but I’m hitting invalid identifier error, or “unexpected keyword ON” errors.
  2. Is there an easier way to accomplish this merge without doing two separate json OBJECT CONSTRUCT queries?

I’ve included the JSON samples below

Generated from a table

And another

Generated using


EDIT: Attempting the answer suggested by @Felipe Hoffa still doesn’t work. code below:

gives me a SQL compilation error: error line 23 at position 3 invalid identifier 'RS'

I’m also struggling to create temporary tables in this way:

but I get

Advertisement

Answer

How to fix the query: You need to add quotes to "_id":

enter image description here

Setup:

Update: If you then want to combine both objects, you could solve this with a simple assign() JS UDF:

enter image description here

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement