|
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 SELECT abc();
- Executing dynamicly created queries
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;
Page 34
|