From: | Marko Tiikkaja <marko(at)joh(dot)to> |
---|---|
To: | Greg Stark <stark(at)mit(dot)edu> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: count_nulls(VARIADIC "any") |
Date: | 2015-08-12 17:33:22 |
Message-ID: | 55CB8362.8030204@joh.to |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 2015-08-12 7:23 PM, Greg Stark wrote:
> On Wed, Aug 12, 2015 at 6:18 PM, Marko Tiikkaja <marko(at)joh(dot)to> wrote:
>> Will finish this up for the next CF, unless someone wants to tell me how
>> stupid this idea is before that.
>
> I'm kind of puzzled what kind of schema would need this.
The first example I could find from our schema was specifying the URL
for a Remote Procedure Call. You can either specify a single request
URI, or you can specify the pieces: protocol, host, port, path. So the
constraints look roughly like this:
CHECK ((fulluri IS NULL) <> (protocol IS NULL)),
CHECK ((protocol IS NULL) = ALL(ARRAY[host IS NULL, port IS NULL,
path IS NULL]))
Obviously the second one would be much prettier with count_nulls().
The other example is an OOP inheritance-like schema where an object
could be one of any X number of types. You could write that:
CHECK ((a IS NULL)::int + (b IS NULL)::int + (c IS NULL)::int) = 1)
or just:
CHECK (count_nulls(a,b,c) = 1)
The first example could be redesigned with three tables, but that seems
like a cure worse than the disease.
.m
From | Date | Subject | |
---|---|---|---|
Next Message | Pavel Stehule | 2015-08-12 17:35:23 | Re: count_nulls(VARIADIC "any") |
Previous Message | Peter Geoghegan | 2015-08-12 17:32:45 | Re: count_nulls(VARIADIC "any") |