Re: Help with error date_trunc() function.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Miguel Angel Prada <mprada(at)hoplasoftware(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Help with error date_trunc() function.
Date: 2024-04-05 16:37:47
Message-ID: 1344783.1712335067@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Miguel Angel Prada <mprada(at)hoplasoftware(dot)com> writes:
> I would need help to know what could be happening to cause the error
> when using the /date_trunc/ function.

EXPLAIN would be informative, but I bet what is happening is that the
date_trunc condition is being pushed down to the scan of pg_class,
since it mentions no variables that aren't available there. Then it
can get evaluated on tables whose names don't match the pattern you
expect. I doubt it's more than luck that PG 15 isn't doing the
same thing.

The usual recommendation for fixing this kind of thing is to insert an
optimization fence to keep the WHERE clause from being pushed down.
You could add "OFFSET 0" in the sub-select, or convert it into a
materialized CTE.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message intmail01 2024-04-05 17:17:43 Function can not use the 'NEW' variable as a direct parameter inside trigger function?
Previous Message Miguel Angel Prada 2024-04-05 16:23:42 Help with error date_trunc() function.