pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: prevot morvan <prevotmorvan@yahoo.fr>
To: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Issue with SQL query causing unintended consequences in database
Date: Fri, 6 Jan 2023 12:56:41 +0000 (UTC)
Message-ID: <1815939917.12528321.1673009801704@mail.yahoo.com> (raw)
References: <1815939917.12528321.1673009801704.ref@mail.yahoo.com>

Dear PostgreSQL bug team,
I am writing to report an issue I encountered when running an SQL query on my database.
I ran the following query:

 UPDATE   nf_job SET   status = 'TO_DO',   error_message = NULL FROM   nf_job n   JOIN formality f ON n.formality_id = f.id WHERE   f.liasse_number IN ('J00011156148', 'J00011416104');


To my surprise, this query erased ALL of the status and error_messages in the nf_jobs table, rather than just changing two lines as I had intended.
Upon reviewing the documentation for SELECT and UPDATE at the following links:
SELECT: https://www.postgresql.org/docs/current/sql-select.htmlUPDATE: https://www.postgresql.org/docs/curre...

I noticed that the SELECT statement allows for the use of "JOIN", but the UPDATE statement does not. This leads me to believe that it should have been a syntax error to include "JOIN" in an UPDATE statement. However, no syntax error was thrown and the query seemed to attempt to run anyway, resulting in the unintended consequences described above.
I would be grateful if the team could take a look into this issue and let me know if there is any way to prevent this from happening in the future.
Thank you in advance for your help.
Sincerely,Émile PRÉVOT

view thread (2+ messages)  latest in thread

Message-ID: <1815939917.12528321.1673009801704@mail.yahoo.com>
Permalink:  ../1815939917.12528321.1673009801704@mail.yahoo.com/
Also on:    postgresql.org/message-id/1815939917.12528321.1673009801704@mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: prevotmorvan@yahoo.fr
  Subject: Re: Issue with SQL query causing unintended consequences in database
  In-Reply-To: <1815939917.12528321.1673009801704@mail.yahoo.com>
  References: <1815939917.12528321.1673009801704.ref@mail.yahoo.com> <1815939917.12528321.1673009801704@mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox