Re: [PATCH] Support for Array ELEMENT Foreign Keys - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [PATCH] Support for Array ELEMENT Foreign Keys
Date
Msg-id 6256.1350613614@sss.pgh.pa.us
Whole thread Raw
In response to Re: [PATCH] Support for Array ELEMENT Foreign Keys  (Marco Nenciarini <marco.nenciarini@2ndquadrant.it>)
Responses Re: [PATCH] Support for Array ELEMENT Foreign Keys  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: [PATCH] Support for Array ELEMENT Foreign Keys  (Andrew Dunstan <andrew@dunslane.net>)
List pgsql-hackers
Marco Nenciarini <marco.nenciarini@2ndquadrant.it> writes:
> Please find the attached refreshed patch (v2) which fixes the loose ends
> you found.

I've started looking at this patch, and the first thing I notice is that
the syntax doesn't work.  It's ambiguous, and this:
 %left        JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL /* kluge to keep xml_whitespace_option from causing
shift/reduceconflicts */ %right        PRESERVE STRIP_P
 
+ %nonassoc    ELEMENT  %%

is not in any way an acceptable fix.  All that that will do is cause an
arbitrary choice to be made when it's not clear what to do.  Half the
time the arbitrary choice will be wrong.  Consider for example

regression=# create table t1 (f1 int[] default 4! element references t2);
ERROR:  column "element" does not exist

The parser has resolved the ambiguity about whether "!" is an infix or
postfix operator by assuming it's infix.  (Yeah, I realize we've "fixed"
some similar cases with precedence hacks, but they are cases that were
forced on us by brain-dead syntax choices in the SQL standard.  We don't
need to go there for syntax we're making up ourselves.)

We could get around that by making ELEMENT a fully reserved word, but
I don't think that's a really acceptable solution.  ELEMENT is reserved
according to more recent versions of the SQL standard, but only as a
built-in function name, and in any case reserving it is very likely to
break people's existing applications.

Another possibility is to forget about the column constraint ELEMENT
REFERENCES syntax, and only support the table-constraint syntax with
ELEMENT inside the column list --- I've not checked, but I think that
syntax doesn't have any ambiguity problems.

Or we could go back to using ARRAY here --- that should be safe since
ARRAY is already fully reserved.

Or we could choose some other syntax.  I'm wondering about dropping the
use of a keyword entirely, and instead using '[]' decoration.  This
wouldn't work too badly in the table constraint case:
FOREIGN KEY (foo, bar[]) REFERENCES t (x,y)

but I'm less sure where to put the decoration for the column constraint
case.

Thoughts?
        regards, tom lane



pgsql-hackers by date:

Previous
From: Daniel Farina
Date:
Subject: Re: Deprecating RULES
Next
From: Ants Aasma
Date:
Subject: Re: [RFC] CREATE QUEUE (log-only table) for londiste/pgQ ccompatibility