Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Uyxkg-0000f0-HG for pgsql-sql@arkaria.postgresql.org; Tue, 16 Jul 2013 05:24:42 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Uyxkf-0005IA-HO for pgsql-sql@arkaria.postgresql.org; Tue, 16 Jul 2013 05:24:41 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Uyxke-0005I3-Fn for pgsql-sql@postgresql.org; Tue, 16 Jul 2013 05:24:40 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Uyxkb-0000dF-IE for pgsql-sql@postgresql.org; Tue, 16 Jul 2013 05:24:39 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id r6G5OXVa000318; Tue, 16 Jul 2013 01:24:33 -0400 (EDT) From: Tom Lane To: Stefan Sylla cc: pgsql-sql@postgresql.org Subject: Re: update column based on postgis query on anther table In-reply-to: <51E4B5A5.4040805@gmx.de> References: <51E4B5A5.4040805@gmx.de> Comments: In-reply-to Stefan Sylla message dated "Tue, 16 Jul 2013 09:53:25 +0700" Date: Tue, 16 Jul 2013 01:24:33 -0400 Message-ID: <317.1373952273@sss.pgh.pa.us> X-Pg-Spam-Score: 0.4 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Stefan Sylla writes: > Now I want to use a trigger function to automatically update the column > 'id_test1_poly' in tabel 'test1_point': > /**/ > create or replace function test1_point_get_id_test1_poly() returns > trigger as $$ > begin > new.id_test1_poly=test1_point_get_id_test1_poly(new.id); > return new; > end; > $$ > language plpgsql volatile; > -- create trigger for function: > create trigger test1_point_get_id_test1_poly > after insert or update on test1_point for each row execute procedure > test1_point_get_id_test1_poly(); I think you need that to be a BEFORE insert or update trigger. In an AFTER trigger, it's too late to affect the stored row. regards, tom lane -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql