Timezone locale consistency for functional indexes

From: Olav Gjerde <olav(at)backupbay(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Timezone locale consistency for functional indexes
Date: 2017-06-12 12:25:23
Message-ID: CAJ7kQyHeg9ta8wwBW1dJoubUHRh+ZnJeMMNOWNyH4Jx++oWbEA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a table that I try create an functional index on like this:

CREATE INDEX my_index_name
ON opening_hours (
opening_hours_type,
EXTRACT(YEAR FROM date),
EXTRACT(MONTH FROM date)
)

But I get the following error: functions in index expression must be
marked IMMUTABLE

But if I change it to:

CREATE INDEX my_index_name
ON opening_hours (
opening_hours_type,
EXTRACT(YEAR FROM date AT TIME ZONE 'UTC'),
EXTRACT(MONTH FROM date AT TIME ZONE 'UTC')
)
The index will be created.

On other systems it could be the oppsite, that it only works without
the additional AT TIME ZONE

On all systems, the default Timezone in postgresql.conf is set to UTC
and show timezone; return UTC. Additionally show lc_time; returns
nb_NO.UTF-8

What kind of system settings could cause this behaviour? We run
Ubuntu Linux 16.04 and Postgresql 9.6

Another question is, should I just create immutable functions wrappers
for this instead?

--
Kind Regards / Med Vennlig Hilsen

Olav Grønås Gjerde

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alex Kliukin 2017-06-12 12:25:44 Re: Why restore_command is called for existing files in pg_xlog?
Previous Message pinker 2017-06-12 08:25:09 Re: Huge Pages - setting the right value