~/ learn/ postgresql/ cards/ PL/pgSQL & triggers
1 of 2

Create a PL/pgSQL function price_band(p numeric) returning 'budget' (<12), 'standard' (<20), or 'premium', then show each book's title and price_band(price) as band. Order by id.

Create a PL/pgSQL function price_band(p numeric) returning 'budget' (<12), 'standard' (<20), or 'premium', then show each book's title and price_band(price) as band. Order by id.

Answer

CREATE FUNCTION price_band(p numeric) RETURNS text AS BEGIN IF p < 12 THEN RETURN 'budget'; ELSIF p < 20 THEN RETURN 'standard'; ELSE RETURN 'premium'; END IF; END; LANGUAGE plpgsql; SELECT title, price_band(price) AS band FROM books ORDER BY id;

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/7b7cfc95-2de4-4a3f-a169-d9d0c457a60a/flashcard utf-8 LF