Re: Rules and Command Status - update/insert/delete rule with series of commands in action - Mailing list pgsql-general

From Alban Hertroys
Subject Re: Rules and Command Status - update/insert/delete rule with series of commands in action
Date
Msg-id F8C371B8-F290-4482-983E-4FD3DDD61A7D@gmail.com
Whole thread Raw
In response to Re: Rules and Command Status - update/insert/delete rule with series of commands in action  ("johnlumby@hotmail.com" <johnlumby@hotmail.com>)
List pgsql-general
> On 31 May 2024, at 00:34, johnlumby@hotmail.com wrote:
>
> On 5/30/24 4:56 PM, David G. Johnston wrote:

(…)

>>  If anything is done it would have to be new syntax.
>>
>>
> A much bigger task surely.
>
> On 5/30/24 5:19 PM, Adrian Klaver wrote:
>>
>> 2) Use INSTEAD OF triggers:
>>
>>
>
> Unfortunately the same functionality as in my example with the RULE is not supported for triggers on views :   from
themanual 
> INSTEAD OF triggers may only be defined on views, and only at row level;
>
> A RULE is essentially a statement-level operation which is what I need for this particular case.      A row-level
triggerwould not work because it cannot "see" the query causing it to be fired,   and also ,  (most importantly) is not
firedat all if no rows match the original query,     whereas a RULE is always in effect regardless of which rows are
involved.before.      I should add that the RULE I showed in my example is not the only RULE being used on this view  -
  there are other conditional RULEs,   and the combined effect is of being able to change the effect of the original
statementinto a set of new statements,   one of which does what is needed. 
>
> And if you are now inclined to say "well,    maybe the application itself is poorly written and should be changed"  -
 I would have to agree,    but that is not mine to change. 
>
> But I suppose that my next question,   given what you both say about the RULE system being a dead-end,  is whether
thereis any likelihood of supporting an INSTEAD OF trigger on a view at statement level?   Maybe that stands more
chanceof going somewhere? 

What you’re attempting to do boils down to adding a virtualisation layer over the database.

Several middleware products exist that provide data virtualisation, products that are accessed as a database (or as a
webservice, or both) that pass on queries to connected systems. The virtualisation layer rewrites those queries between
thedata sources and the user-visible virtual database connection and between generalised SQL and native dialects and
languages.

If existing products support your particular use-case though, namely rewriting operational data-storage queries to
data-sourcespecific DML statements and then report the correct number of affected rows back, I don’t know. 

However, an important reason that PG rules are deprecated (as I understand it) is that it is very hard to get right for
generatedcolumns, which are operations with side-effects (such as incrementing a sequence value, for example) that are
includedin those queries rewritten by the specified rules. 
I doubt that a data virtualisation layer would be able to solve that particular problem.

Nevertheless, considering what path you’re on, they may be worth looking at. I don’t think there are any open-source
initiatives(unfortunately), they’re all commercial products AFAIK, and not cheap. With a suitable use-case they can be
rathervaluable tools too though. 

Regards,

Alban Hertroys
--
Als je de draak wilt steken met iemand,
dan helpt het,
als die een punthoofd heeft.







pgsql-general by date:

Previous
From: Mukesh Tanuku
Date:
Subject: Re: [pgpool-general: 9106] Postgres/pgpool HA failover process
Next
From: Laurenz Albe
Date:
Subject: Re: ERROR: found xmin from before relfrozenxid; MultiXactid does no longer exist -- apparent wraparound