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

From: Greg Sabino Mullane <htamfids(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, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
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:02:56
Message-ID: CAKAnmmL9EP6BpVUfytjb32j_ZfO=tT63WOQy4dHSs8enaR=ziA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Wed, Jan 22, 2025 at 10:59 AM Rajni Bobal <rajnibobal(at)gmail(dot)com> wrote:

> SELECT delete_from_table1('commandlog','commandlog','cmdid','cmdtime <
> extract(epoch FROM (current_date - 15))*1000',500);
>

(putting aside many other issues for now)

It would help to see the exact output you are getting. The query as written
above cannot work with the functions you gave, which have the column name
as the FOURTH parameter, and the where clause as the THIRD.

EXECUTE 'DELETE from ' || quote_ident(tblname) ||
> ' where $1 in (select $1 from ' || quote_ident(sel_tblname) ||
> ' where ' || wherecon || ' limit $2 ) '
> USING colname, batchsize;
>

Use FORMAT instead:

EXECUTE FORMAT(
'DELETE from %I WHERE %I IN (SELECT %I FROM %I WHERE %s LIMIT %s)',
tblname, colname, colname, sel_tblname, wherecon, batchsize
);

Cheers,
Greg

--
Crunchy Data - https://www.crunchydata.com
Enterprise Postgres Software Products & Tech Support

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2025-01-23 15:03:54 Re: BUG #18774: Not the required output of the query used in the function(delete_from_table1) in postgresql9.4
Previous Message Rajni Bobal 2025-01-23 14:54:36 Re: BUG #18774: Not the required output of the query used in the function(delete_from_table1) in postgresql9.4