10

I have two tables that I am trying to UNION. Column id in table1 is of type STRING. I do not have that column in table2 so I am writing SELECT NULL AS id FROM table2 but BigQuery thinks that column id in table2 is of type INT64.

I get this error - Column 2 in UNION ALL has incompatible types: STRING, INT64.

Query works if I write SELECT "" AS id FROM table2 instead.

2
  • 4
    In your upper query select cast(null as string) Commented Feb 1, 2018 at 9:01
  • 1
    ..or STRING(NULL) should work as well Commented Feb 1, 2018 at 10:21

1 Answer 1

7

SELECT id FROM table1 UNION ALL SELECT CAST(NULL AS STRING) FROM table2

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

Comments

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.