Re: insert rule instead oddity

From: Sim Zacks <sim(at)compulab(dot)co(dot)il>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: insert rule instead oddity
Date: 2007-03-13 14:36:50
Message-ID: et6d01$nmi$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I would think the rule qualification would tell the system not to run the rule in the event that it
does not meet the qualification. According to the docs:
What is a rule qualification? It is a restriction that tells when the actions of the rule
should be done and when not. This qualification can only reference the pseudorelations NEW and/or
OLD, which basically represent the relation that was given as object (but with a special meaning).

In the event that the qualification is met, the database only does the rule and not the insert, as
is directed by the Instead keyword and as I am expecting. However, in the event that the
qualification is not met then I would expect it to not do the rule as I understand it to say in the
docs.

Sim

Martijn van Oosterhout wrote:
> On Tue, Mar 13, 2007 at 02:15:01PM +0200, Sim Zacks wrote:
>> select version()
>> "PostgreSQL 8.0.1 on i686-pc-linux-gnu, compiled by GCC
>> i686-pc-linux-gnu-gcc (GCC) 3.3.5 (Gentoo Linux 3.3.5-r1, ssp-3.3.2-3,
>> pie-8.7.7.1)"
>>
>> I am sure that I must have missed something here because I read the
>> documentation and searched the forums and it all seems fairly
>> straightforward.
>
> Rules don't work the way you think they do. They're sort of macro
> expansions. What's ahppening when you insert is the rule splits it into
> two statements, one insert and one update, with the where conditions
> adjusted. Depending on the order I imagine that it could do both.
>
> I don't think rules can do what you want. What you need in the SQL
> MERGE command, but postgresql doesn't support that. A stored procedure
> could do it.
>
> Have a nice day,

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Guy Fraser 2007-03-13 14:43:17 Re: OT: Canadian Tax Database
Previous Message alexander krohn 2007-03-13 14:33:34 Re: one-to-one schema design question and ORM