0

I have a code in the DB trigger like

_association_id bigint;
if TG_OP = 'INSERT' then
     select concat('NEW.',association_field_id) INTO _association_id from association_audit_configs where table_name = TG_TABLE_NAME;
elsif TG_OP = 'DELETE' then
     select  concat('OLD.',association_field_id) INTO _association_id from association_audit_configs where table_name = TG_TABLE_NAME;
end if;

I have columns names in association_field_id column of association_audit_configs table. Example: If I have the value as computer_id in association_field_id, I want to assign the value of OLD.computer_id to _association_id. But its considering as "OLD.computer_id" eventually getting error as input syntax for type bigint: "OLD.computer_id". How can I make it to consider as OLD.computer_id while assigning to _association_id ?

2

1 Answer 1

0

cast the records to hstore.

if TG_OP = 'INSERT' then
     select hstore(NEW)->association_field_id INTO _association_id from association_audit_configs where table_name = TG_TABLE_NAME;
elsif TG_OP = 'DELETE' then
     select  hstore(OLD)->association_field_id INTO _association_id from association_audit_configs where table_name = TG_TABLE_NAME;
end if;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.