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

From David G. Johnston
Subject Re: BUG #18774: Not the required output of the query used in the function(delete_from_table1) in postgresql9.4
Date
Msg-id CAKFQuwa+sb1aK+64rBHxqt6R2twi8CTned5_FzBTDu3z4oMk9Q@mail.gmail.com
Whole thread Raw
In response to Re: BUG #18774: Not the required output of the query used in the function(delete_from_table1) in postgresql9.4  (Rajni Bobal <rajnibobal@gmail.com>)
List pgsql-bugs
On Thu, Jan 23, 2025 at 7:54 AM Rajni Bobal <rajnibobal@gmail.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.

pgsql-bugs by date:

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