Re: BUG #18097: Immutable expression not allowed in generated at
David G. Johnston <david.g.johnston@gmail.com>
From: "David G. Johnston" <david.g.johnston@gmail.com>
To: "jim@jimkeener.com" <jim@jimkeener.com>, "pgsql-bugs@lists.postgresql.org" <pgsql-bugs@lists.postgresql.org>
Date: 2023-09-08T15:11:42Z
Lists: pgsql-bugs, pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Ensure we preprocess expressions before checking their volatility.
- f07a3039c72b 16.2 landed
- abd1b1325d60 12.18 landed
- 9bd0f74eac19 14.11 landed
- 9057ddbefe7e 15.6 landed
- 743ddafc7124 17.0 landed
- 5c11104c7d20 13.14 landed
On Thursday, September 7, 2023, PG Bug reporting form < noreply@postgresql.org> wrote: > The following bug has been logged on the website: > > Bug reference: 18097 > Logged by: Jim Keener > Email address: jim@jimkeener.com > PostgreSQL version: 15.0 > Operating system: Linux > Description: > > However, the following DOES NOT work with an error of (ERROR: generation > expression is not immutable): > > * alter table test_table add created_local text GENERATED ALWAYS AS > (EXTRACT(isoyear FROM created_at AT TIME ZONE 'America/New_York') || '|' || > EXTRACT(week FROM created_at AT TIME ZONE 'America/New_York')) STORED; > > Given that casting shouldn't "increase" the immutability of an expression, > and expression indexes need also be immutable afaik, I think that there is > a > bug somewhere here? > Casting very much can be a non-immutable activity, dates being the prime example, and I presume going from numeric to text is indeed defined to be stable hence the error. This is probably due to needing to consult locale for deciding how to represent the decimal places divider. This is one of the few places, assuming you write the function to set an environment fixing locale to some know value like you did with the time zones, where creating an immutable function around a stable expression makes sense. David J.