11

Is it possible to do something like the following in BigQuery to quickly generate sample input?

SELECT * FROM values ('david',10), ('tom',20)

Or does it only accept the verbose SELECT ... UNION ALL ... format:

select 'david' name, 10 age union all select 'tom', 20;

1 Answer 1

21

Consider below as an option

SELECT * FROM UNNEST([
    STRUCT('david' as name,10 as age), 
    ('tom', 20),
    ('jon', 30)
  ])    

OR

SELECT * FROM UNNEST([STRUCT<name STRING, age INT64>
    ('david',10), ('tom', 20), ('jon', 30)
  ])          

both give you quick dummy data to play with

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

cool, yea the second approach is easy enough to remember I think I'll use that -- thanks!
This is super helpful but note to reader: it doesn't work if you just have a single column. Add a second dummy column and you'll be fine. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.