datahack
datahack

Reputation: 691

Snowflake stored procedure parameter problem

I want to log an error that happens in stored procedure:

catch (ERROR)  {
      snowflake.execute({sqlText: sql_update_log_command, binds: [RUN_ID, PROCESS_ID,'error', 0, ERROR.message] });
        return "Failed: " + ERROR.message;
    }

sql_update_log_command executes procedure "update_process_log" and binds those 5 arguments. But, when error happens columns that should contain error message stays empty. Error was something like this:

"Failed: Numeric value '$METADATA$FILE_ROW_NUMBER' is not recognized File 'data/stage/20220104/user_activity/20220104-172435475.csv.gz', line 2, character 1 Row 1, column $METADATA$FILE_ROW_NUMBER If you would like to continue loading when an error is encountered, use other values such as 'SKIP_FILE' or 'CONTINUE' for the ON_ERROR option. For more information on loading options, please run 'info loading_data' in a SQL client."

Procedure "update_process_log" signature:

create or replace procedure metadata.update_process_log(
    RUN_ID FLOAT, 
    PROCESS_ID FLOAT, 
    PROCESS_STATUS VARCHAR,
    NUM_OF_RECORDS FLOAT,
    ERROR_MSG VARCHAR)
returns string
  language javascript

Does it look like dollar sign $ is making a problem? How can this be handled?

Upvotes: 1

Views: 431

Answers (1)

datahack
datahack

Reputation: 691

I found a solution in this question - Snowflake working with stored procedure on error handling

Basically you have to escape single quotes before logging rows:

err.message.replace( /'/g , "''" )

Upvotes: 2

Related Questions