Re: Possible to create canonicalized range type without being superuser?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Paul Jungwirth <pj(at)illuminatedcomputing(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Possible to create canonicalized range type without being superuser?
Date: 2016-07-05 22:28:25
Message-ID: CAKFQuwY=t_hQH-G3Bj78X182=u94C7g=itWjJ0Sgv4iHhuUQzA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jul 5, 2016 at 5:37 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Paul Jungwirth <pj(at)illuminatedcomputing(dot)com> writes:
> > The problem is this (tried on 9.3 and 9.5):
> > db=> create type inetrange;
> > ERROR: must be superuser to create a base type
> > So I'm wondering whether there is any way around this circle without
> > being a superuser?
>
> The only other obvious way to deal with this is to allow the canonical
> function to be defined after the range type is created, and then added to
> the type via an ALTER TYPE command. But then you have an interval where
> the type is not restricted, in which you might store values that aren't
> canonical.
>

​Can the canonical function be definitionally optional but runtime
required? That is, have it only be an error to use a type lacking a
canonical function? If so I think a usable idiom is that for types that
don't want to canonicalize (i.e., presently have a NULL assigned) they
would make an explicit declaration by doing something like:

CREATE TYPE int4range AS RANGE (subtype = int4, canonical = int4_identity);

Now you have a window where the type is incompletely defined and when the
missing canonical function is encountered the system balks. At some future
point a function can be associated via ALTER TYPE which makes the type
completely defined.

CREATE TYPE inetrange AS RANGE (subtype = inet, canonical = NULL);
ALTER TYPE inetrange SET PROPERTY canonical = inet_canonicalizer;

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Luís Eduardo Oliveira Lizardo 2016-07-06 00:08:33 Is it possible to use an EVENT TRIGGER to validate a TRIGGER?
Previous Message trafdev 2016-07-05 22:21:06 Re: pg_dump fundenental question