alim1990
alim1990

Reputation: 4972

Snowflake how to transform a select query result and save it into an array of object?

I need to select specific rows from a table and transform the result into an array.

Let's say I have this query:

SELECT * FROM TEMP_TABLE WHERE ID > 1000

The result will be about 4 rows having the following structure:

enter image description here

I need to convert the result into an array of object.

I tried using:

select array_construct(*) from my_table;

But it transformed each row into an array with no keys like: [1, 'TEST', 2, 'DATA'].

I am using a JavaScript procedure.

How to transform an sql select rows result into a variant on Snowflake?

Upvotes: 1

Views: 3084

Answers (1)

Sergiu
Sergiu

Reputation: 4578

Use:

SELECT OBJECT_CONSTRUCT(*) FROM my_table;

rather than array_construct.

Upvotes: 2

Related Questions