Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jJO7D-0003Uf-Ba for pgsql-docs@arkaria.postgresql.org; Tue, 31 Mar 2020 21:08:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jJO7C-0008V0-8y for pgsql-docs@arkaria.postgresql.org; Tue, 31 Mar 2020 21:08:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jJO7C-0008Up-2v for pgsql-docs@lists.postgresql.org; Tue, 31 Mar 2020 21:08:06 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jJO79-0005Ms-UN for pgsql-docs@lists.postgresql.org; Tue, 31 Mar 2020 21:08:05 +0000 Received: from bruce by momjian.us with local (Exim 4.92) (envelope-from ) id 1jJO78-000549-99; Tue, 31 Mar 2020 17:08:02 -0400 Date: Tue, 31 Mar 2020 17:08:02 -0400 From: Bruce Momjian To: mib@nic.at, pgsql-docs@lists.postgresql.org Subject: Re: Wrong insert before trigger examples Message-ID: <20200331210802.GC17676@momjian.us> References: <158089540905.1098.15071165437284409576@wrigleys.postgresql.org> <20200313225637.GB10187@momjian.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200313225637.GB10187@momjian.us> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Patch applied back through PG 10. --------------------------------------------------------------------------- On Fri, Mar 13, 2020 at 06:56:37PM -0400, Bruce Momjian wrote: > On Wed, Feb 5, 2020 at 09:36:49AM +0000, PG Doc comments form wrote: > > The following documentation comment has been logged on the website: > > > > Page: https://www.postgresql.org/docs/12/ddl-partitioning.html > > Description: > > > > Hi, > > > > I just noticed that the example in 5.11.3.1. Point 5 contains an "before > > insert trigger" which will not work anymore (I think since Postgres 12). > > This trigger is not needed anymore and causes an error message. > > Sorry for the delay in replying. I was able to successfully create the > trigger: > > CREATE TABLE measurement ( > city_id int not null, > logdate date not null, > peaktemp int, > unitsales int > ); > > CREATE TABLE measurement_y2006m02 ( > CHECK ( logdate >= DATE '2006-02-01' AND logdate < DATE '2006-03-01' ) > ) INHERITS (measurement); > > CREATE INDEX measurement_y2006m02_logdate ON measurement_y2006m02 (logdate); > > CREATE OR REPLACE FUNCTION measurement_insert_trigger() > RETURNS TRIGGER AS $$ > BEGIN > INSERT INTO measurement_y2008m01 VALUES (NEW.*); > RETURN NULL; > END; > $$ > LANGUAGE plpgsql; > > CREATE TRIGGER insert_measurement_trigger > BEFORE INSERT ON measurement > FOR EACH ROW EXECUTE FUNCTION measurement_insert_trigger(); > > There are actually two definitions of 'measurement' in the docs above, > and you might have used the partitioned one: > > CREATE TABLE measurement ( > city_id int not null, > logdate date not null, > peaktemp int, > unitsales int > ) PARTITION BY RANGE (logdate); > > I have developed the attached patch to clarify which definition to use. > I am not sure if more extensive changes are needed. > > -- > Bruce Momjian https://momjian.us > EnterpriseDB https://enterprisedb.com > > + As you are, so once was I. As I am, so you will be. + > + Ancient Roman grave inscription + > diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml > index 8d3a0d1c22..d2588876c0 100644 > --- a/doc/src/sgml/ddl.sgml > +++ b/doc/src/sgml/ddl.sgml > @@ -4103,8 +4103,8 @@ ALTER INDEX measurement_city_id_logdate_key > Example > > > - We use the same measurement table we used > - above. To implement partitioning using inheritance, use > + We use the non-partitioned measurement > + table above. To implement partitioning using inheritance, use > the following steps: > > -- Bruce Momjian https://momjian.us EnterpriseDB https://enterprisedb.com + As you are, so once was I. As I am, so you will be. + + Ancient Roman grave inscription +