Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 7AFAFB5FAE5 for ; Tue, 31 May 2011 11:47:01 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 02603-02 for ; Tue, 31 May 2011 14:46:54 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-iw0-f174.google.com (mail-iw0-f174.google.com [209.85.214.174]) by mail.postgresql.org (Postfix) with ESMTP id 286CAB5FF53 for ; Tue, 31 May 2011 11:46:54 -0300 (ADT) Received: by iwn34 with SMTP id 34so3678268iwn.19 for ; Tue, 31 May 2011 07:46:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type:content-transfer-encoding; bh=5ET+Bfhlxv/Mvk/VNq61opchAZIRvQ61HtgFfogjLXQ=; b=rG+G4bu63HIKCgmbSehwj16kwNEaYOwZqoQGuQkCwx0D3pMA+/DbnxftAJNiD6rRCN WdCOlrglJPYQivbQ9yNFeK1yOlceYT0lsJ+1N9l/g/q9cla/J9ofYpxSfiHbPYUkuBLJ pZZtoYUAUQLHYKBBuHgPxoU5rFg6T00/NI54A= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=kmjgJhNPBHxgMlMwyh8wpvrc7JSBZ1x4V3ndDdy5CujF1s/67dzatD4RsWjcKXCni1 pUE3ChPYRpJy4OfAlw7aeBFS0NmuS3kh8wv3CKZs6k6+ZRpAC9rkbJxxc2ENGXzQv8ss tIrVmqFUwL7udOoiA21rbfxnzTeZQX7lhssjo= Received: by 10.231.63.83 with SMTP id a19mr7745849ibi.104.1306853214132; Tue, 31 May 2011 07:46:54 -0700 (PDT) MIME-Version: 1.0 Received: by 10.231.59.199 with HTTP; Tue, 31 May 2011 07:46:34 -0700 (PDT) In-Reply-To: References: From: Kevin Crain Date: Tue, 31 May 2011 07:46:34 -0700 Message-ID: Subject: Re: Re: Order of evaluation in triggers for checks on inherited table partitions To: pgsql-sql@postgresql.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.335 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_ENVFROM_END_DIGIT=1.553, FREEMAIL_FROM=0.001, RFC_ABUSE_POST=0.001, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201105/182 X-Sequence-Number: 35466 Okay, I figured out what is going on. Even though I was running the update on the master table the trigger was not being applied because it was actually being ran using the child table where the record to be updated resided. So the trigger function was being skipped and it was running as an ordinary update, hence the error. In order to get this to work I had to add a trigger for each child table as well to call my update function trigger. --Kevin Crain On Tue, May 31, 2011 at 6:40 AM, Kevin Crain wrote= : > Can procedural languages be used in rules? =C2=A0I didn't see any example= s > in the documentation that suggested something like this could be done > using rules. > > --Kevin Crain > > On Mon, May 30, 2011 at 2:21 AM, Jasen Betts wrote: >> On 2011-05-27, Kevin Crain wrote: >>> I am trying to create a trigger on updates to a table that is >>> partitioned. =C2=A0The child tables are partitioned by month and includ= e >>> checks on a timestamp field. >> >>> However when I try to update an existing record with a >>> timestamp that would place it in a child table different from the >>> child table it is in I get an error due to the check on the child >>> table it is currently in. =C2=A0My best guess as to what is happening i= s >>> that the trigger is evaluating the check before it evaluates the >>> trigger function and thus cannot tell that the update to the original >>> table should never take place. =C2=A0I have included an example below. = =C2=A0The >>> error that results is "new row for relation "t_foo_2011_6" violates >>> check constraint "t_foo_2011_6_f_timestamp_check"" >> >> the problem is the check is running before the trigger. >> perhaps you can use a rule instead of a trigger? >> >> -- >> =E2=9A=82=E2=9A=83 100% natural >> >> >> -- >> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) >> To make changes to your subscription: >> http://www.postgresql.org/mailpref/pgsql-sql >> >