Getting all columns name in an table using trigger function in postgresql -


how can column names , values in trigger function because need validate column values before inserting table.i have tried below code.if know column name means can value using new object in trigger function new.mycolumnname.but here need column name dynamically...

    create function insert_update_validate() returns trigger $$     declare     begin     in 0..(tg_argv-1) loop          if tg_argv[i] null                                 raise exception 'cannot have null value', new.tg_argv[i];     end loop;     return new;     end;     $$ language plpgsql; 

since hstore part of postgresql, casting row hstore primary method iterate on columns, @ least in plpgsql context. otherwise language doesn't provide construct extract column names rows.

basically it's iterating on each(store(new)). here's skeleton may use:

create function insert_update_validate() returns trigger $$ declare  k text;  v text; begin   k,v in select key,value each(hstore(new)) loop     if v null       raise exception 'value null column %', k;     end if;   end loop;   return new; end; $$ language plpgsql; 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -