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)


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to