Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YiM0k-0006A6-Fe for pgsql-bugs@arkaria.postgresql.org; Wed, 15 Apr 2015 12:01:42 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YiM0j-0000bZ-Qn for pgsql-bugs@arkaria.postgresql.org; Wed, 15 Apr 2015 12:01:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YiM0h-0000bQ-Tk for pgsql-bugs@postgresql.org; Wed, 15 Apr 2015 12:01:39 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YiM0V-0007nl-Nv for pgsql-bugs@postgresql.org; Wed, 15 Apr 2015 12:01:38 +0000 Received: from pro.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t3FC1N8n028189; Wed, 15 Apr 2015 08:01:23 -0400 From: Tom Lane To: "David G. Johnston" cc: dwayne.towell@gmail.com, "pgsql-bugs@postgresql.org" Subject: Re: BUG #13053: type names pollute function name space In-reply-to: References: <20150414212454.5205.74148@wrigleys.postgresql.org> Comments: In-reply-to "David G. Johnston" message dated "Tue, 14 Apr 2015 15:54:38 -0700" Date: Wed, 15 Apr 2015 08:01:23 -0400 Message-ID: <3402.1429099283@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org "David G. Johnston" writes: > On Tue, Apr 14, 2015 at 2:24 PM, 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