Re: How do I upsert depending on a second table? - Mailing list pgsql-general

From Adrian Klaver
Subject Re: How do I upsert depending on a second table?
Date
Msg-id 22052a80-6461-4bc3-b75b-7b1063982101@aklaver.com
Whole thread Raw
In response to Re: How do I upsert depending on a second table?  (Samuel Marks <samuelmarks@gmail.com>)
Responses Re: How do I upsert depending on a second table?
List pgsql-general
On 9/24/25 10:02, Samuel Marks wrote:
> On Wed, Sep 24, 2025 at 10:13 AM Adrian Klaver 

> Yes but it's meant to divide by zero. That cancels the whole transaction 
> stopping it from going through. It being a transaction lets me guarantee 
> that at point of update or insert [upsert] the org owner matches the 
> requestor.
> 
> I would preference a single statement (one semicolon) solution; but for 
> now at least this works 🤷

I don't have enough experience with below to come up with an off the top 
of my head examples, but they look like they may offer alternatives.

MERGE:

https://www.postgresql.org/docs/current/sql-merge.html

and/or Row level Security:

https://www.postgresql.org/docs/current/ddl-rowsecurity.html

In above link see example that starts below the phrase:

"... If it is necessary to consult other rows or other tables to make a 
policy decision, that can be accomplished using sub-SELECTs, or 
functions that contain SELECTs, in the policy expressions. ... "


-- 
Adrian Klaver
adrian.klaver@aklaver.com



pgsql-general by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: Index rebuilding strategy
Next
From: Ron Johnson
Date:
Subject: Re: Index rebuilding strategy