In Redshift, this can only be done in a procedure. https://docs.aws.amazon.com/redshift/latest/dg/stored-procedure-trapping-errors.html