ALTER TABLE my_table
ADD date date GENERATED ALWAYS AS ((timezone( 'Asia/Kolkata'::text,
COALESCE( timestamp_with_timezone_1, timestamp_with_timezone_2 ) ))::date) STORED;
I get the following error
[42P17] ERROR: generation expression is not immutable
I have tried using '+5:30' instead of 'Asia/Kolkata' I have tried using at time zone directly with the column, like this:
ALTER TABLE my_table
ADD COLUMN date date GENERATED ALWAYS AS (
COALESCE(
(timestamp_with_timezone_1 AT TIME ZONE 'Asia/Kolkata')::date,
(timestamp_with_timezone_2 AT TIME ZONE 'Asia/Kolkata')::date
)
) STORED;
Throws same error.
Can anyone suggest a solution.
ALTER TABLE my_table
ADD date date GENERATED ALWAYS AS ((timezone( 'Asia/Kolkata'::text,
COALESCE( timestamp_with_timezone_1, timestamp_with_timezone_2 ) ))::date) STORED;
I get the following error
[42P17] ERROR: generation expression is not immutable
I have tried using '+5:30' instead of 'Asia/Kolkata' I have tried using at time zone directly with the column, like this:
ALTER TABLE my_table
ADD COLUMN date date GENERATED ALWAYS AS (
COALESCE(
(timestamp_with_timezone_1 AT TIME ZONE 'Asia/Kolkata')::date,
(timestamp_with_timezone_2 AT TIME ZONE 'Asia/Kolkata')::date
)
) STORED;
Throws same error.
Can anyone suggest a solution.
Share Improve this question edited Mar 17 at 13:21 Shh asked Mar 17 at 13:00 ShhShh 1,01610 silver badges21 bronze badges 3 |1 Answer
Reset to default 0Do set your time zone after the COALESCE
(and it's shorter to write!):
ALTER TABLE my_table
ADD date date GENERATED ALWAYS AS
(COALESCE( timestamp_with_timezone_1, timestamp_with_timezone_2 ) AT TIME ZONE 'Asia/Kolkata')
STORED;
See it in this fiddle.
timestamp_with_timezone_1
and_2
have one? – Guillaume Outters Commented Mar 17 at 14:51