-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: SQL Procedure definitions wrapped in $$
that contain $$
lead to syntax error
#3422
Comments
$$
that contain $$
lead to syntax error
For the specific procedure above, heres the query Terraform synthesized to execute to create: CREATE PROCEDURE "SBX_DATA_ADMINISTRATION"."CALLABLES"."SPROC__DYNAMIC_TABLE_REFRESH" () RETURNS STRING(16777216) LANGUAGE SQL RETURNS NULL ON NULL INPUT COMMENT = 'This stored procedure is used to refresh dynamic tables based on the environment manually.' EXECUTE AS CALLER AS $$DECLARE -- noqa: PRS
DYN_TABLES RESULTSET;
RESOLVED_ENVIRONMENT VARCHAR;
BEGIN
-- First query will be our master table, what we use to loop through
SHOW DYNAMIC TABLES IN ACCOUNT;
-- If this evaluates to PRD, we want to refresh all tables in the production environment
RESOLVED_ENVIRONMENT := IFF(CURRENT_DATABASE() = 'DATA_ADMINISTRATION', 'PRD', SPLIT_PART(CURRENT_DATABASE(), '_', 1));
-- Now we can assign the query to this result set, we only want production tables
DYN_TABLES := (
SELECT CONCAT_WS('.', "database_name", "schema_name", "name") AS FULLY_QUALIFIED_NAME
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
WHERE "database_name" ILIKE :RESOLVED_ENVIRONMENT || '%'
);
-- Assign the cursor for the resultset
LET DYN_CURSOR CURSOR FOR DYN_TABLES;
-- Now, we can loop through the resultset and refresh each table
FOR RECORD IN DYN_CURSOR DO
BEGIN
-- First thing, dynamically create a task to refresh the table
EXECUTE IMMEDIATE $$
CREATE OR REPLACE TASK SPROC__DYNAMIC_TABLE_REFRESH__MIDNIGHT_PST__ || RECORD.FULLY_QUALIFIED_NAME
AS (
EXECUTE IMMEDIATE 'ALTER DYNAMIC TABLE ' || RECORD.FULLY_QUALIFIED_NAME || ' REFRESH;'
);
$$;
SYSTEM$LOG_INFO('Created task to refresh dynamic table: ' || RECORD.FULLY_QUALIFIED_NAME);
EXECUTE IMMEDIATE 'EXECUTE TASK SPROC__DYNAMIC_TABLE_REFRESH__MIDNIGHT_PST__' || RECORD.FULLY_QUALIFIED_NAME;
SYSTEM$LOG_INFO('Executed task to refresh dynamic table: ' || RECORD.FULLY_QUALIFIED_NAME);
EXCEPTION
WHEN STATEMENT_ERROR THEN
SYSTEM$LOG_WARN('Error refreshing dynamic table: ' || RECORD.FULLY_QUALIFIED_NAME);
WHEN OTHER THEN
RAISE;
END;
END FOR;
END;
$$ --terraform_provider_usage_tracking {"json_schema_version":"1","version":"v1.0.3","resource":"snowflake_procedure_sql","operation":"create"} |
Hey @kharigardner 👋 |
Terraform CLI Version
1.5.7
Terraform Provider Version
1.0.3
Company Name
PowerSchool
Terraform Configuration
Category
category:resource
Object type(s)
No response
Expected Behavior
When a Snowflake SQL procedure contains
$$
to denote literals within a Snowflake scripting block, I expect the SQL synthesized to use th esimpleCREATE PROCEDURE ... AS ...
syntax, without covering the SQL block in$$
delimiter.Actual Behavior
The procedure definition was wrapped in
$$
asCREATE PROCEDURE ... AS $$ ... $$
, leading to a query syntax error.Steps to Reproduce
$$
.terraform apply
How much impact is this issue causing?
Low
Logs
No response
Additional Information
No response
Would you like to implement a fix?
The text was updated successfully, but these errors were encountered: