Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sCwUl-0096mT-4b for pgsql-general@arkaria.postgresql.org; Fri, 31 May 2024 07:16:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sCwUk-009XQS-SY for pgsql-general@arkaria.postgresql.org; Fri, 31 May 2024 07:16:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sCwUk-009XQJ-HM for pgsql-general@lists.postgresql.org; Fri, 31 May 2024 07:16:10 +0000 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sCwUg-001dgx-Mh for pgsql-general@lists.postgresql.org; Fri, 31 May 2024 07:16:09 +0000 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-57a1fe63a96so1288221a12.0 for ; Fri, 31 May 2024 00:16:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717139766; x=1717744566; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=4F5NG3Wumj0S2psly0d0Y81dnPndQmUSB4PSCpbwiSM=; b=E7FuRrDz0o4r3JVroWMMmJ1sOmcJLom1hk/twZgsmMPgX/Bv02CiisMTUnijQvdO6s 4UT5FhEaoxI3TO9I5fFk0VOP4obBnmaPFw3pTwIn5KpGsFXyCkedDrcWWPltGhwU7RfV jiu5DNOWPWIYjdbo56lgRXAnAtB4vqw9tZWj/o8h3snEwerPRWeBvUB78HFYRmVrZRQY LxkLVW7pN6Qt/lI7AcCmTSfm8v4B13M1E274MBaaAns+yDopvOQMIRhB+h0wnq0hxKbi jU4zMv4Jsv4YVC6Bk7ODb/Wlm0nkySP4yhSVk2+Q786guB/3N4T22BqbBlKiCBIrulR5 Rdag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717139766; x=1717744566; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4F5NG3Wumj0S2psly0d0Y81dnPndQmUSB4PSCpbwiSM=; b=qziI4peDxL5ogqbqW9jhHkRSonpoipYbgRIQ3KSteP1S+aSMjvVEn6gYuL91c0Im6b 7pZTCwWAb0SAZJxnWK4evL/gqBFYyt0k8RGvReRX+UihD8JZjkoa2j+asIRZOuV2sygE e6pAf2gVtGMGaJ8jDlw9I7iYoUZTgFz2HVmcYOUwOMsMMkDS+5Zq+UKGE4jvbKX3KAnw jt50VnKibycC5MyNIB2cF7k+CHtGs2OBYEUGclBZZ6i64VRfbnPacpLG1ZvigUkt9xFR yYH0P84vAQmretuDrPhz1xQkkZbVGAg6S0hkjEfWPTXf6KSYj4jSQUYJfrsrfu/+XZN6 ZKfA== X-Gm-Message-State: AOJu0Yyjkp7t/lQcTyuDCR1MjRVTIixkh9+OK0YtYu8CN8LUQrYccs21 wXz5HbnCrbm3dktTb2g1Pqz1kOVTbyaFz+rcafF7LG12tQhtdmcj X-Google-Smtp-Source: AGHT+IFysttGahazdIxXdYuH/WmVaGMt/8T8kF7YDBVlm8hgs5jKr4m4n6Np9B40LsMInJ+no/5hFA== X-Received: by 2002:a50:9e61:0:b0:579:c8cb:ec3d with SMTP id 4fb4d7f45d1cf-57a364eb2b5mr688744a12.37.1717139765592; Fri, 31 May 2024 00:16:05 -0700 (PDT) Received: from smtpclient.apple ([188.212.112.125]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57a3dd301b9sm120548a12.66.2024.05.31.00.16.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 May 2024 00:16:04 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.600.62\)) Subject: Re: Rules and Command Status - update/insert/delete rule with series of commands in action From: Alban Hertroys In-Reply-To: Date: Fri, 31 May 2024 09:15:54 +0200 Cc: pgsql-general , Adrian Klaver , David G Johnston Content-Transfer-Encoding: quoted-printable Message-Id: References: To: John Lumby X-Mailer: Apple Mail (2.3774.600.62) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 31 May 2024, at 00:34, johnlumby@hotmail.com wrote: >=20 > On 5/30/24 4:56 PM, David G. Johnston wrote: (=E2=80=A6) >> If anything is done it would have to be new syntax. =20 >>=20 >>=20 > A much bigger task surely.=20 >=20 > On 5/30/24 5:19 PM, Adrian Klaver wrote: >>=20 >> 2) Use INSTEAD OF triggers:=20 >>=20 >>=20 >=20 > Unfortunately the same functionality as in my example with the RULE is = not supported for triggers on views : from the manual > INSTEAD OF triggers may only be defined on views, and only at row = level; >=20 > A RULE is essentially a statement-level operation which is what I need = for this particular case. A row-level trigger would not work = because it cannot "see" the query causing it to be fired, and also , = (most importantly) is not fired at 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 statement into a set of new = statements, one of which does what is needed. >=20 > 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. >=20 > But I suppose that my next question, given what you both say about = the RULE system being a dead-end, is whether there is any likelihood of = supporting an INSTEAD OF trigger on a view at statement level? Maybe = that stands more chance of going somewhere? What you=E2=80=99re 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 web service, or both) = that pass on queries to connected systems. The virtualisation layer = rewrites those queries between the data 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-source specific DML = statements and then report the correct number of affected rows back, I = don=E2=80=99t know. However, an important reason that PG rules are deprecated (as I = understand it) is that it is very hard to get right for generated = columns, which are operations with side-effects (such as incrementing a = sequence value, for example) that are included in 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=E2=80=99re on, they may be worth = looking at. I don=E2=80=99t think there are any open-source initiatives = (unfortunately), they=E2=80=99re all commercial products AFAIK, and not = cheap. With a suitable use-case they can be rather valuable tools too = though. Regards, Alban Hertroys -- Als je de draak wilt steken met iemand, dan helpt het, als die een punthoofd heeft.