Good day! I tried to form a trigger by automatically adding a key (incremental) field to the table. Give a true example of how to use a sequence to make a trigger with an autoincrement number.
My incorrect (erroneous) option is below:
CREATE FUNCTION trigger_s_before_lns () RETURNS trigger AS BEGIN NEW.ns=nvl(NEW.ns,to_char(nextval('s_seq'),'99999')) return NEW; END; LANGUAGE plpgsql;
Where s_seq is a sequence.