Yun Zhang
Yun Zhang

Reputation: 5518

SELECT INTO with BigQuery

MySQL/Oracle/Teradata has SELECT ... INTO FROM ... to get value from a table and assign them to variable(s). How can I do this with BigQuery?

SELECT 
    c1, c2, c3, ...
INTO 
    @v1, @v2, @v3,...
FROM 
    table_name
WHERE 
    condition;

Upvotes: 5

Views: 24827

Answers (2)

Yun Zhang
Yun Zhang

Reputation: 5518

The counterpart in BigQuery is a SET statement getting value from a subquery.

See this example:

SET (v1, v2, v3) = (SELECT AS STRUCT c1, c2, c3 FROM table_name WHERE condition LIMIT 1)

It behaves exactly the same as the query in question.

See more examples from documentation.

Upvotes: 6

Mikhail Berlyant
Mikhail Berlyant

Reputation: 173200

I think the proper way would be as below:

SET (v1, v2, v3) = (SELECT AS STRUCT c1, c2, c3 FROM table_name WHERE condition LIMIT 1)

Upvotes: 0

Related Questions