Snowflake: Load an indicator column stored procedure

Viewed 53

I have 2 columns in a table, load and insert. This table is loaded from files. The load and insert basically just say how many rows from the file have been loaded and how many have been inserted. In a stored procedure, if both of these are 0 I want the indicator column to return Fail or else return Success

1 Answers

The query is straigtforward:

SELECT 
  CASE WHEN load = 0 AND "insert" = 0 THEN 'Fail'
       ELSE 'Success'
  END AS indicator
FROM tab
-- WHERE ...

If there is need to pass parameter, then the query should be extended with WHERE clasue.


Such column could also be added as computed column:

CREATE TABLE tab (
  load INT,
  "insert" INT,
  indicator TEXT AS IFF(load = 0 AND "insert" = 0, 'Fail', 'Success')
);

INSERT INTO tab(load, "insert") VALUES (1,0), (0,0);
SELECT * FROM tab;

Output:

enter image description here

Related