BigQuery Using a Declared variable as sql constraint to produce another Declared variable

25 Views Asked by At

Is it possible to use another declared variable as a sql constraint to produce another declared variable?

declare names_list_1 array<string>;
declare names_list_2 array<string>;

declare query1 string;
declare query2 string;

set names_list_1 = ['Angelica', 'Eliza', 'Peggy'];

/*brute forcing pull*/
set query1 = "create temp table Not_Schyuler_Sister as select distinct CHARACTER_NM from HAMILTON_CAST 
where CHARACTER_NM is not in (select * from unnest(names_list_1))";

set query2 = /* forcing query 1 output to an string array */

execute immediate query1;
execute immediate query2 into names_list_2;


Unfortunately, I kept on having this error when executing query 1 :

Query error: Unrecognized name: names_list_1 at [1:XXXX]

Is there another way for use the declared array string as a sql constraint? or it's just not possible for BQ.

Query error: Unrecognized name: names_list_1 at [1:XXXX]

0

There are 0 best solutions below