BUG #18097: Immutable expression not allowed in generated at

Поиск
Список
Период
Сортировка
Искать
От
PG Bug reporting form
Тема
BUG #18097: Immutable expression not allowed in generated at
Дата
Msg-id
18097-ebb179674f22932f@postgresql.org
Список
Дерево обсуждения
BUG #18097: Immutable expression not allowed in generated at PG Bug reporting form <noreply@postgresql.org>
Re: BUG #18097: Immutable expression not allowed in generated at "David G. Johnston" <david.g.johnston@gmail.com>
Re: BUG #18097: Immutable expression not allowed in generated at James Keener <jim@jimkeener.com>
Re: BUG #18097: Immutable expression not allowed in generated at Tom Lane <tgl@sss.pgh.pa.us>
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:        

Given this table:

CREATE TABLE test_table (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
created_at timestamptz NOT NULL DEFAULT now()
);

The following work:

* alter table test_table add created_local_y text GENERATED ALWAYS AS
(EXTRACT(isoyear FROM created_at AT TIME ZONE 'America/New_York')) STORED;

* alter table test_table add created_local_w text GENERATED ALWAYS AS
(EXTRACT(week FROM created_at AT TIME ZONE 'America/New_York')) STORED;

* alter table test_table add created_local text GENERATED ALWAYS AS
(EXTRACT(isoyear FROM created_at AT TIME ZONE 'America/New_York')::text ||
'|' || EXTRACT(week FROM created_at AT TIME ZONE 'America/New_York')::text)
STORED;

* CREATE INDEX ON test_table ((EXTRACT(isoyear FROM created_at AT TIME ZONE
'America/New_York') || '|' || EXTRACT(week FROM created_at AT TIME ZONE
'America/New_York')));

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?

Thank you,
Jim

В списке pgsql-bugs по дате отправления
От: Michael Paquier
Дата:
От: Nikolay Samokhvalov
Дата:
FAQ