Re: BUG #18774: Not the required output of the query used in the function(delete_from_table1) in postgresql9.4

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Rajni Bobal <rajnibobal(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Vik Fearing <vik(at)postgresfriends(dot)org>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #18774: Not the required output of the query used in the function(delete_from_table1) in postgresql9.4
Date: 2025-01-23 15:03:54
Message-ID: CAKFQuwa+sb1aK+64rBHxqt6R2twi8CTned5_FzBTDu3z4oMk9Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Thu, Jan 23, 2025 at 7:54 AM Rajni Bobal <rajnibobal(at)gmail(dot)com> wrote:

> Colname is variable here, it value should be replaced in param string
> ($1).
>

Regardless of the specific characters it is replaced with the important
point is that your first query introduces an identifier and the second a
string literal. This is why they behave differently.

There is no bug here - the queries are doing what they are supposed to.
The use of string literals makes the second filter always evaluate to true
so long as at least one row is returned and the value of $1 is not null (in
this case your where clause is "cmdid' IN ('cmdid', 'cmdid', ...)". Thus
it deletes all rows in the table.

David J.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2025-01-23 18:09:48 Re: BUG #18783: 2025-01-23 03:55:06.243 GMT [22929] LOG: postmaster became multithreaded 2025-01-23 03:55:06.243 GM
Previous Message Greg Sabino Mullane 2025-01-23 15:02:56 Re: BUG #18774: Not the required output of the query used in the function(delete_from_table1) in postgresql9.4