darold / pgbadger

A fast PostgreSQL Log Analyzer
http://pgbadger.darold.net/
PostgreSQL License
3.45k stars 348 forks source link

pgbadger 12.2 : Fail to normalize query containing `IN (cast($1 as date))` #799

Closed grib0 closed 7 months ago

grib0 commented 9 months ago

The following request fails to be normalized correctly with pgbadger 12.2

select public.t_journee.jou_id, public.t_journee.jou_date from public.t_journee where (public.t_journee.jou_date in (cast($1 as date), cast($2 as date))
select public.t_journee.jou_id, public.t_journee.jou_date from public.t_journee where (public.t_journee.jou_date in (cast($1 as date), cast($2 as date), cast($3 as date))

I would expect to have the queries normalized in one query instead of 2

select public.t_journee.jou_id, public.t_journee.jou_date from public.t_journee where (public.t_journee.jou_date in (...))

pgbadger -f stderr postgresql_log_pb_cast.log

image

postgresql_log_pb_cast.log

darold commented 9 months ago

Hi,

The normalization is correct. Actually the normalization concern the parameters for bind queries. pgbadger use this normalization with bind parameters to create the examples. In your sample log, the query is the following:

LOG:  duration: 5627.478 ms  execute <unnamed>: select public.t_journee.jou_id, public.t_journee.jou_date from public.t_journee where ((public.t_journee.jou_date in (cast($1 as date), cast($2 as date), cast($3 as date)))

and the bind parameters are given in another log line:

DETAIL:  parameters: $1 = '2023-11-06', $2 = '2023-11-07', $3 = '2023-11-08', $4 = '2023-11-09'

to be able to construct a valid example, the cast call must remain in the normalized query otherwise they will be lost.