Skip to content

Instantly share code, notes, and snippets.

@apstndb
Last active August 9, 2022 08:49
Show Gist options
  • Save apstndb/ace2f48b2318bdb308e8f7e802addd0c to your computer and use it in GitHub Desktop.
Save apstndb/ace2f48b2318bdb308e8f7e802addd0c to your computer and use it in GitHub Desktop.

https://issuetracker.google.com/issues/35905569#comment111

DECLARE v1 INT64 DEFAULT 123;
DECLARE v2 INT64 DEFAULT 123;
BEGIN
    SET v1 = @v1;
    SET v2 = @v2;
EXCEPTION WHEN ERROR THEN
    -- nop
END;
SELECT v1, v2;
# works if all parameters are set
$ cat query_parameter.sql | bq query --nouse_legacy_sql --parameter=v1:INT64:1 --parameter=v2:INT64:2 --quiet
SELECT v1, v2; -- at [9:1]
+----+----+
| v1 | v2 |
+----+----+
|  1 |  2 |
+----+----+

# works if all parameters are not set
$ cat query_parameter.sql | bq query --nouse_legacy_sql --quiet
SELECT v1, v2; -- at [9:1]
+-----+-----+
| v1  | v2  |
+-----+-----+
| 123 | 123 |
+-----+-----+

# not works if parameters are partially set
$ cat query_parameter.sql | bq query --nouse_legacy_sql --parameter=v1:INT64:1 --quiet
Error in query string: Error processing job '{project_id}:bqjob_r14be0572274cc08e_0000018281c414ce_1': Unknown named query parameter: v2 at [1:1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment