pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: dwayne.towell@gmail.com
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: BUG #13053: type names pollute function name space
Date: Wed, 15 Apr 2015 08:01:23 -0400
Message-ID: <3402.1429099283@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwbbc1DVJri7XfCceXwBXBv8MP9p8kcw8z0uY4s96reffg@mail.gmail.com>
References: <20150414212454.5205.74148@wrigleys.postgresql.org>
	<CAKFQuwbbc1DVJri7XfCceXwBXBv8MP9p8kcw8z0uY4s96reffg@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Tue, Apr 14, 2015 at 2:24 PM, <dwayne.towell@gmail.com> wrote:
>> CREATE TYPE x AS (id int);
>> CREATE FUNCTION _x(text) RETURNS SETOF x AS $$ SELECT 1 WHERE $1='hi'; $$
>> LANGUAGE SQL;
>> SELECT _x('hi');
>> ERROR:  array value must start with "{" or dimension information
>> LINE 1: SELECT _x('hi');

> It is finding the auto-magically created type "array x" aka: "x[]​".  For
> reasons unknown to myself the underlying representation type is named "_x".

> Then, since "type 'literal'" and "type('literal') are equivalent to
> "'literal'::type", SELECT _x('literal') becomes ambiguous and its (_x)
> treatment as a type precedes its treatment as a function name.

Yeah.  See the documentation at
http://www.postgresql.org/docs/9.2/static/typeconv-func.html
as well as the further commentary on the CREATE CAST reference page.

> I would have thought that maybe you could access the original function
> using double-quotes: SELECT "_x"('hi'); but that appears to be
> incorrect...and not obviously useful even if it worked.

No, the way to think about this is that it's a overloaded-function
problem.  You can force the correct function to be called if the arguments
are of exactly the expected types, which an unknown-type literal isn't:

regression=# SELECT _x('hi'::text);
 _x  
-----
 (1)
(1 row)

That works because the exact-match case precedes the cast-function case
in the function resolution rules.

> FWIW in the example provided I would prefer to have the CREATE FUNCTION
> call fail with a "function already exists" error - though I do not believe
> that is strictly correct.  Maybe "unsupported function signature - matching
> array of type x already exists"...?

That won't happen because there is not in fact any conflicting function.
In the first place, the cast function was never really created (see the
footnote at the bottom of the doc page I cited); in the second place,
if it had been created it would likely be considered to have "unknown"
as the input type.

A more plausible way to eliminate the conflict would be to get rid of the
casts-as-function-calls notation; but that would break an awful lot of
existing client code, so I think the odds of us doing that are about nil.

			regards, tom lane


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



view thread (4+ messages)

Message-ID: <3402.1429099283@sss.pgh.pa.us>
Permalink:  ../3402.1429099283@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3402.1429099283@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, dwayne.towell@gmail.com
  Subject: Re: BUG #13053: type names pollute function name space
  In-Reply-To: <3402.1429099283@sss.pgh.pa.us>
  References: <20150414212454.5205.74148@wrigleys.postgresql.org> <CAKFQuwbbc1DVJri7XfCceXwBXBv8MP9p8kcw8z0uY4s96reffg@mail.gmail.com> <3402.1429099283@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox