Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Snowflake – Getting invalid identifier error while passing variables between SQL Stored Procs

I have a Snowflake SQL stored procedure from where I’m trying to call the SYSTEM$SEND_EMAIL function, but its erroring out as below:

`create or replace procedure testsproc()
RETURNS VARCHAR
language sql 
as
$$
BEGIN
  SELECT * FROM non_existent_table;
EXCEPTION
  WHEN OTHER THEN
    LET LINE := SQLCODE || ': ' || SQLERRM;
    INSERT INTO myexception VALUES (:LINE); -- this line works
    call SYSTEM$SEND_EMAIL('MYEMAIL','abc@mail.com','Errors!!',LINE); -- this line is throwing the error invalid identifier 'LINE' (line 320)
    return line;
END;
$$`

I tried passing :LINE to system$send_email, it still isn’t working. What am I doing wrong?

Any help is much appreciated.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It’s missing a colon, the same colon the script uses in the previous line:

Fixed:

    call SYSTEM$SEND_EMAIL('MYEMAIL','abc@mail.com','Errors!!', :LINE); 

With that, I get the desired exception in my email:

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading