Reputation: 1297
I want to create a view dynamically with a string generated by a temporary function. The code below fails with Creating views with temporary user-defined functions is not supported
. How can I create the view without permanently registering the function?
CREATE TEMP FUNCTION CreateViewString()
RETURNS STRING
AS (("select 1 as col"));
EXECUTE IMMEDIATE "CREATE OR REPLACE VIEW `project.dataset.view` AS " || CreateViewString()
Upvotes: 0
Views: 1416
Reputation: 1916
I'm posting this answer for posterity. This is a known issue that the BigQuery team is aware of and improvements have been under consideration. You can also STAR
the issue to receive automatic updates and give it traction by referring to this link. Suggested workarounds are as follows.
Upvotes: 1
Reputation: 1297
As a workaround one can store the result of the function and then drop the function.
DECLARE viewString STRING;
CREATE TEMP FUNCTION CreateViewString()
RETURNS STRING
AS (("select 1 as col"));
SET viewString = CreateViewString();
DROP FUNCTION CreateViewString;
EXECUTE IMMEDIATE "CREATE OR REPLACE VIEW `project.dataset.view` AS " || viewString
Upvotes: 1