2016-11-07 1 views

Antwort

1

NEW and OLD are special record variables in Triggerfunktionen. Sie können sie nicht wie durch Arrays durchlaufen.

Eine Möglichkeit, eine Schleife durch Spalten einer (bekannte) Datensatz oder Zeile: Transformation json oder jsonb, und dann:

CREATE OR REPLACE FUNCTION foo() 
    RETURNS trigger AS 
$BODY$ 
DECLARE 
    js jsonb := to_jsonb(NEW); 
    col text; 
BEGIN 
    FOR col IN SELECT * FROM jsonb_object_keys(js) 
    LOOP 
     RAISE NOTICE '%: %', col, js->>col; 
    END LOOP; 

    RETURN NEW; 
END 
$BODY$ 
    LANGUAGE plpgsql VOLATILE; 
Verwandte Themen