RAISE levels in SQL
One message, several volumes: DEBUG stays silent, NOTICE informs, WARNING nags.
-- RAISE speaks at several volumes; % splices values into the message.
DO $$
DECLARE
vests INTEGER;
BEGIN
SELECT stock
INTO vests
FROM products
WHERE sku = 'PFD-M';
RAISE DEBUG 'debug is silent by default';
RAISE NOTICE 'vests on hand: %', vests;
RAISE WARNING 'vest stock at %: reorder', vests;
END;
$$;
How it works
RAISE DEBUGis filtered out at default settings — free tracing.RAISE NOTICE 'vests on hand: %', vestssplices the value at the%.RAISE WARNINGescalates without aborting anything.
Keywords and builtins used here
BEGINDECLAREDOENDFROMINTEGERINTOSELECTWHERE
The run, in numbers
- Lines
- 14
- Characters to type
- 304
- Tokens
- 41
- Three-star pace
- 70 tpm
At the three-star pace of 70 tokens a minute, this run takes about 35 seconds.
Step 1 of 4 in Errors & triggers, step 17 of 23 in PostgreSQL Stored Procedures.