Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 48F48632507 for ; Wed, 6 Jan 2010 17:01:15 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 51918-09 for ; Wed, 6 Jan 2010 21:01:00 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-yx0-f192.google.com (mail-yx0-f192.google.com [209.85.210.192]) by mail.postgresql.org (Postfix) with ESMTP id F148B63356B for ; Wed, 6 Jan 2010 17:01:03 -0400 (AST) Received: by yxe30 with SMTP id 30so19860031yxe.29 for ; Wed, 06 Jan 2010 13:01:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=wzD8P5Ld57GjSzA1d7Txw6IQ9dRldC0Z6IKut1cP23E=; b=wxbXA2uvXuqL6qb6rmFZVBZtHtCz8pyqJSybcEeSkZa64Ro7IE9sDaEUcwHNZRCFws k9WcXufLzrziXbVZPWRT2Iv6PQeTdCryXpP4jVITRByYFWUEnuTcFOlkk2BBa239WkhM YtTgh5MKe4aVNZuxPBzhqLPB9BZc/MCoRDLeg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=JAGWyzsUCVOyTWrr5tQSKSxndBUhC+rHRY+c9nKo5qXYKbisZLpA7iFXzOYX6fxxQr yCteXsKqx5V0aXYH+SvXfVEIQM+Q3H9GDXDnjl4KQ69kY4aItINU1wU9W45a4BWylieF yAh3mwQMxCwxtPLPX3nAAujC0IUkV7drrXIPw= MIME-Version: 1.0 Received: by 10.101.128.2 with SMTP id f2mr13226380ann.174.1262811662580; Wed, 06 Jan 2010 13:01:02 -0800 (PST) In-Reply-To: <87fx6jm0fl.fsf@kolob.sebmags.homelinux.org> References: <87fx6jm0fl.fsf@kolob.sebmags.homelinux.org> Date: Wed, 6 Jan 2010 13:01:02 -0800 Message-ID: <396486431001061301m1fa305fav211a98bb3b9f62f1@mail.gmail.com> Subject: Re: Fwd: conditional rule not applied From: Richard Broersma To: Seb Cc: pgsql-sql@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.958 tagged_above=-10 required=5 tests=AWL=-1.547, BAYES_00=-2.599, FH_DATE_PAST_20XX=3.188 X-Spam-Level: X-Archive-Number: 201001/7 X-Sequence-Number: 33543 On Wed, Jan 6, 2010 at 12:40 PM, Seb wrote: > I'm trying to create a rule to be applied on update to a view that > consists of two joined tables. =A0Table 'shoes' below is left-joined with > table 'shoelaces' in the view 'footwear'. =A0I'd like to create a simple > update rule on the view, only if the value of a common column > corresponds to an inexistent record in 'shoelaces', so the result is an > INSERT into 'shoelaces' with the new record: A couple of year's ago, I was seriously looking into update-able views. But from my experience, I'm sorry to say you not going to find a robust solution to this problem. There are at least three problems with joined table update-able views: 1) You can only issue insert-update-delete statements that will only affect one row. 2) You cannot serialize the update of a view's virtual row like you can with a table's row. This allow leave the possibility of concurrent update anomalies. 3) Application frameworks that use optimistic locking or use the updated row count for validation will complain (and automatically roll-back your work) when you attempt to perform an update. The official use for update-able views is for limiting the results from a *single* base table. Having said all of this, it is possible to do what your describing. I've seen Keith Larson make update-able views from a composite of selected UNION and FULL OUT JOIN queries. But his solution was extremely hackish. --=20 Regards, Richard Broersma Jr. Visit the Los Angeles PostgreSQL Users Group (LAPUG) http://pugs.postgresql.org/lapug