On Mon, 18 Nov 2002, Roberto de Amorim wrote:
> Hi all,
>
> I did some Trigger to set default values for each row interted.
> so, I'm using NEW.ID = NEXTVAL(''products_id_seq'');
> but the column do not assum this value...
> must I execute any other command before to set a value for NEW?
>
> CREATE OR REPLACE FUNCTION "f_products"() RETURNS "opaque" AS '
> BEGIN
> NEW.ID = NEXTVAL(''products_id_seq'');
> RETURN NEW;
> END' LANGUAGE 'plpgsql'
>
> CREATE TRIGGER "t_classes" AFTER INSERT ON "products" FOR EACH ROW EXECUTE
> PROCEDURE f_products();
Apart from the fact that serial or a default is easier, if you want to
modify the row to be inserted (or the updated value of an update), you
want a BEFORE trigger, not an AFTER one.