PL/PgSQL

  • Statements
    • SELECT INTO [row | record | var1,var2,var3 ...]
SELECT INTO rec * FROM a WHERE i > 10 LIMIT 1;
IF NOT FOUND THEN
	RAISE EXCEPTION ''No records where i is greater than 10'';
END IF;
    • When more than one tuple returned, only first tuple stored in 'rec'
  • Calling a function from within PL/PgSQL
    • PERFORM query;
PERFORM SELECT abc();
    • Result is discarded
  • Executing dynamicly created queries
    • EXECUTE query-string
DECLARE
newtab text;
rec RECORD;
BEGIN
FOR rec IN SELECT DISTINCT substring(w FOR 1) as letter FROM words LOOP
	newtab := ''CREATE TABLE words_'' || rec.letter || '' (w text, id int)'';
	EXECUTE newtab;
END LOOP;
Prev

Next

Page 34