0
votes
  • I am trying to delete a record from a snowflake table using a sql script file through snowflake cli.
  • For example from the table PIPELINE_CONFIG_DETAILS I want to delete the records where DAG_NAME = 'file_to_snowflake'
  • And I want to make this as a generic one, so that the user can pass the table name and Filter condition as in input parameter to achieve the goal.
  • For this I am passing the table name and where clause as the variables to the SQL file.
  • The variable where clause is throwing me Invalid identifier error.
  • I tried passing the variable values as DAG_NAME = 'file_to_snowflake' as well as DAG_NAME IN ('file_to_snowflake'), both values throwing the same error.

Below is the command I am passing in the snowsql: with = in filter condition snowsql -c development -f sql_template_filter_parameter.sql -D SF_TABLE='"TestDb"."Dev"."PIPELINE_CONFIG_DETAILS"' -D SF_SQL_FILTER=DAG_NAME='file_to_snowflake'

Below is the error I am getting: With = condition 000904 (42000): SQL compilation error: error line 1 at position 75
invalid identifier '"DAG_NAME='file_to_snowflake'"'

Below is the command I am passing in the snowsql: with IN in the filter condition snowsql -c development -f sql_template_filter_parameter.sql -D SF_TABLE='"SANDPIT"."MCM_SANDBOX"."PIPELINE_CONFIG_DETAILS_3_COLS"' -D SF_SQL_FILTER="DAG_NAME"\ IN('file_to_snowflake') -o remove_comments=tru e

Below is the error I am getting: With IN condition 000904 (42000): SQL compilation error: error line 1 at position 75
invalid identifier '"DAG_NAME IN('file_to_snowflake')"'

Below is the body content of the SQL file. !SET variable_substitution=true;

DELETE FROM "&{SF_TABLE}" WHERE "&{SF_SQL_FILTER}";

SELECT COUNT(*) FROM "&{SF_TABLE}";

Hope I am clear with the use case.

Any little help will be highly appreciated.

Thanks in advance, Raghu.

1

1 Answers

0
votes

Your -D parameter is wrong:

-D SF_SQL_FILTER=DAG_NAME='file_to_snowflake'

You have 3 values and 2 = signs, which makes no sense