typestar

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

  1. RAISE DEBUG is filtered out at default settings — free tracing.
  2. RAISE NOTICE 'vests on hand: %', vests splices the value at the %.
  3. RAISE WARNING escalates without aborting anything.

Keywords and builtins used here

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.

Type this snippet

Step 1 of 4 in Errors & triggers, step 17 of 23 in PostgreSQL Stored Procedures.

← Previous Next →