Re: Patch: shouldn't timezone(text, timestamp[tz]) be STABLE?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Aleksander Alekseev <aleksander(at)timescale(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Patch: shouldn't timezone(text, timestamp[tz]) be STABLE?
Date: 2021-08-30 14:51:46
Message-ID: 1351043.1630335106@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Aleksander Alekseev <aleksander(at)timescale(dot)com> writes:
> There are several overloaded versions of timezone() function. One
> version accepts timezone name and timestamptz and returns timestamp:
> This function is marked as IMMUTABLE and it's possible to use it in
> functional indexes. I believe it's a bug.

That's a deliberate choice IIRC. I agree that the behavior could
change after a tzdata update, but if the standard is that "immutable"
means "no conceivable future code or configuration change could alter
the results", then there's not a lot of functions that will pass that
test :-(.

As a pretty relevant example, we're not going to stop marking text
comparison operators as immutable, even though we know all too well
that the OS' sort order might change underneath us. The loss of
functionality and performance that would result from downgrading
those to stable is just not acceptable. It's better to treat them
as immutable and accept the risk of sometimes having to rebuild
indexes.

I don't see a lot of argument for treating tzdata changes differently
from OS locale changes.

> Other versions of timezone() seem to be fine, except:
> Source code | timetz_zone
> Does anyone know the reason why, unlike other versions, it's marked
> VOLATILE?

Looking at the code, it decides whether to use DST or not based on
the current time ... which it gets using time(NULL). So the volatile
marking is correct for this implementation, because it could change
intra-query. This seems like a pretty dumb choice though: I'd think
it'd make more sense to use the value of now() as the referent.
Then it could be stable, and it'd also be faster because it wouldn't
need its own kernel call.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Noah Misch 2021-08-30 14:52:56 Re: AIX: Symbols are missing in libpq.a
Previous Message hubert depesz lubaczewski 2021-08-30 14:45:51 Re: Can we get rid of repeated queries from pg_dump?