Domain based on TIMEZONE WITH TIME ZONE

From: Ben Hood <ben(at)relops(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Domain based on TIMEZONE WITH TIME ZONE
Date: 2018-05-10 08:03:42
Message-ID: 06EAD729-DC35-4E48-AB25-C42F7FA19C28@relops.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I'm using a domain to specialize the built in TIMEZONE WITH TIME ZONE type. I want to sanity check this approach before continuing to use this.

I want to prevent timestamps with non-UTC offsets from getting inserted into the database. Having a UTC-only database at the schema level means no app, proc, script or load operation can inadvertently supply a local time offset.

The domain is defined as:

CREATE DOMAIN UTC_TIMESTAMP AS TIMESTAMP WITH TIME ZONE CHECK (EXTRACT(TIMEZONE FROM VALUE) = 0);
CREATE TYPE UTC_RANGE AS RANGE ( SUBTYPE = UTC_TIMESTAMP );

My potentially misguided assumption is that I am effectively re-using a check constraint across the schema.

Is this crazy?

Am I missing the point of how Postgres stores TIMEZONE WITH TIME ZONE internally?

Thanks in advance,

Ben

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ben Hood 2018-05-10 08:10:03 Re: Domain based on TIMEZONE WITH TIME ZONE
Previous Message tango ward 2018-05-10 05:25:34 Re: ON CONFLICT DO UPDATE