Re: Help with error date_trunc() function. - Mailing list pgsql-sql

From Tom Lane
Subject Re: Help with error date_trunc() function.
Date
Msg-id 1344783.1712335067@sss.pgh.pa.us
Whole thread Raw
In response to [MASSMAIL]Help with error date_trunc() function.  (Miguel Angel Prada <mprada@hoplasoftware.com>)
List pgsql-sql
Miguel Angel Prada <mprada@hoplasoftware.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



pgsql-sql by date:

Previous
From: Miguel Angel Prada
Date:
Subject: [MASSMAIL]Help with error date_trunc() function.
Next
From: intmail01
Date:
Subject: [MASSMAIL] Function can not use the 'NEW' variable as a direct parameter inside trigger function?