I'm trying to run a query in redshift where I'm selecting using json_extract_path_text. Unfortunately, some of the JSON entries in this database column are invalid.
What happens: When the query hits an invalid JSON value, it stops with a "JSON parsing error".
What I want: Ignore any rows with invalid JSON in that column, but return any rows where it can parse the JSON.
Why I can't make it do what I want: I don't think I understand error handling in Redshift/Postgres. It should be possible to simply skip any rows that generate errors, but I tried entering EXEC SQL WHENEVER SQLERROR CONTINUE (based on the Postgres docs) and got a "syntax error at or near SQLERROR".
SELECT version()? Are you sure you're not using Amazon RDS PostgreSQL 9.3 instead? As for the command you supplied, that's for Embedded SQL in C (ecpg), and doesn't apply here at all. You'd want a PL/PgSQLBEGIN ... EXCEPTIONblock.BEGIN ... EXCEPTIONblock I'd probably accept it.