From: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
---|---|
To: | Samuel Marks <samuelmarks(at)gmail(dot)com> |
Cc: | Juan Rodrigo Alejandro Burgos Mella <rodrigoburgosmella(at)gmail(dot)com>, pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: How do I upsert depending on a second table? |
Date: | 2025-09-24 23:03:10 |
Message-ID: | 22052a80-6461-4bc3-b75b-7b1063982101@aklaver.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | 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(dot)klaver(at)aklaver(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Ron Johnson | 2025-09-24 23:34:03 | Re: Index rebuilding strategy |
Previous Message | Laurenz Albe | 2025-09-24 21:52:55 | Re: Index rebuilding strategy |