From: | Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk> |
---|---|
To: | Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, David Fetter <david(at)fetter(dot)org>, PG Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Naming of ORDINALITY column (was: Re: Review: UNNEST (and other functions) WITH ORDINALITY) |
Date: | 2013-06-24 03:00:50 |
Message-ID: | E1Uqx1O-000M9b-9R@erlenstar.riddles.org.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
OK, let's try to cover all the bases here in one go.
First, the spec definition of WITH ORDINALITY simply says that the
column name in the result is not equivalent to any other identifier in
the same <table primary> (including the <correlation name>). It is
clear that the intention of the spec is that any non-positional
reference to this column (which is defined as being positionally last)
requires an alias at some point, whether directly attached to the
<table primary> or at an outer level.
Second, all the documentation I've looked at for other databases that
implement this feature (such as DB2, Teradata, etc.) takes it for
granted that the user must always supply an alias, even though the
syntax does not actually require one. None of the ones I've seen
suggest that the ordinality column has a useful or consistent name if
no alias is supplied.
So, while clearly there's nothing stopping us from going beyond the
spec and using a column name that people can refer to without needing
an alias, it would be a significant divergence from common practice in
other dbs. (iirc, it was my suggestion to David to use "?column?" in
the first place for this reason.)
So as I see it the options are:
1. Stick with "?column?" as a warning flag that you're not supposed to
be using this without aliasing it to something.
2. Use some other fixed name like "ordinality" simply to allow people
to do things like select ... from unnest(x) with ordinality; without
having to bother to provide an alias, simply as a convenience, without
regard for consistency with others. (This will result in a duplicate
name if "x" is of a composite type containing a column called
"ordinality", so the caller will have to provide an alias in that
specific case or get an ambiguous reference error. Similarly if using
some other SRF which defines its own return column names.)
3. Generate an actually unique name (probably pointless)
4. Something else I haven't thought of.
My vote remains with option 1 here; I don't think users should be
encouraged to assume that the ordinality column will have a known
name.
--
Andrew (irc:RhodiumToad)
From | Date | Subject | |
---|---|---|---|
Next Message | Josh Berkus | 2013-06-24 03:29:39 | Re: Naming of ORDINALITY column |
Previous Message | Tom Lane | 2013-06-24 02:50:13 | Re: FILTER for aggregates [was Re: Department of Redundancy Department: makeNode(FuncCall) division] |