Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Yi9tD-0001RP-3E for pgsql-bugs@arkaria.postgresql.org; Tue, 14 Apr 2015 23:05:07 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Yi9tC-000790-9F for pgsql-bugs@arkaria.postgresql.org; Tue, 14 Apr 2015 23:05:06 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Yi9tB-00078o-7I for pgsql-bugs@postgresql.org; Tue, 14 Apr 2015 23:05:05 +0000 Received: from mail-pd0-x232.google.com ([2607:f8b0:400e:c02::232]) by makus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Yi9t5-0003UM-Ie for pgsql-bugs@postgresql.org; Tue, 14 Apr 2015 23:05:03 +0000 Received: by pdbqa5 with SMTP id qa5so28880559pdb.1 for ; Tue, 14 Apr 2015 16:04:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:references:in-reply-to:subject:date:message-id :mime-version:content-type:thread-index:content-language; bh=e0wNPpCXE0e90LCI7V7J0xSTaR7nixEIpQ+aT2rL8w0=; b=kbsFdxDFMD17DxIHbPUVUoJ/Zh3psORCCSUHJ5LHmKpHEDK+jG65ql7ygqWdI2sY/9 gEGp73uAELAvmtSXDMvscFncbVzgZXthIPtGLwj3TSuijOFm7KPW2jpodtx/IQOF7Qds eKvLATeMFePLDJqeepq4P66A1Jm44U7JO80ZOvXla/ez45ukwaEhgXE0WJLLabPe1Prf ib19TdWppqgCLLDKgh0Zyk44uI9C316Z93QaYuATbH7hjmrK7ERH4Sxd7AWFh8xrrNct J+T2k68+QGxbVEegCkSZQ7RVQ5IaktUBG+7QUznHUwCDbi7luiu/UOjN5r7NdolgHJ3c lPCg== X-Received: by 10.66.66.108 with SMTP id e12mr41255509pat.31.1429052698396; Tue, 14 Apr 2015 16:04:58 -0700 (PDT) Received: from robust (static-50-53-46-17.bvtn.or.frontiernet.net. [50.53.46.17]) by mx.google.com with ESMTPSA id n3sm2098752pdm.90.2015.04.14.16.04.56 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 14 Apr 2015 16:04:57 -0700 (PDT) From: "Dwayne Towell" To: "'David G. Johnston'" Cc: References: <20150414212454.5205.74148@wrigleys.postgresql.org> In-Reply-To: Subject: Re: BUG #13053: type names pollute function name space Date: Tue, 14 Apr 2015 16:04:54 -0700 Message-ID: <03f801d07707$6c4063e0$44c12ba0$@gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_03F9_01D076CC.BFE18BE0" X-Mailer: Microsoft Outlook 15.0 Thread-Index: AQIJRJ6HHGibigKU6IZqfncb/4He6AKmZ1/wnMZQelA= Content-Language: en-us X-Pg-Spam-Score: -1.7 (-) 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 This is a multipart message in MIME format. ------=_NextPart_000_03F9_01D076CC.BFE18BE0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable I figured it had something to do with array types, given the error, but = still feel like creating the function, when it cannot be called, is an = error. I would appreciate getting an error similar to the one you = described instead of one later when attempting to call the function = since I would have saved me a couple of hours of debugging. I would = appreciate it if the documentation contained some hint that = type-conversion functions were automatically created by prepending an = underscore. (I don=E2=80=99t know how I would have found that nugget = without a better error message but still feel it is missing.) =20 I also tried the quoted-identifier trick and was equally surprised it = didn=E2=80=99t work and then on reflection relieved that it = didn=E2=80=99t either. =20 We have solved the problem by changing our naming convention, given the = usual momentum on projects like this I don=E2=80=99t expect it to be = changed, but better documentation and an better error would be = appreciated. =20 From: David G. Johnston [mailto:david.g.johnston@gmail.com]=20 Sent: Tuesday, April 14, 2015 3:55 PM To: dwayne.towell@gmail.com Cc: pgsql-bugs@postgresql.org Subject: Re: [BUGS] BUG #13053: type names pollute function name space =20 On Tue, Apr 14, 2015 at 2:24 PM, > wrote: The following bug has been logged on the website: Bug reference: 13053 Logged by: Dwayne Towell Email address: dwayne.towell@gmail.com = =20 PostgreSQL version: 9.2.10 Operating system: CentOS Description: The following: =E2=80=8B=E2=80=8B CREATE TYPE x AS (id int); CREATE FUNCTION _x(text) RETURNS SETOF x AS $$ SELECT 1 WHERE $1=3D'hi'; = $$ LANGUAGE SQL; SELECT _x('hi'); produces: ERROR: array value must start with "{" or dimension information LINE 1: SELECT _x('hi'); Which seems wrong. Creating a type named 'x' should not preempt my = function by finding an auto created(?) conversion(?) function. =20 =E2=80=8BTo be more explicit about what is happening here=E2=80=8B: =20 It is finding the auto-magically created type "array x" aka: = "x[]=E2=80=8B". For reasons unknown to myself the underlying = representation type is named "_x". =20 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. =20 I'll admit it seems odd but I'd chalk this up to system oddity and move = on. What is the solution you are looking for anyway? =20 I'm sure there are more surprises relating to types and functions since = functions are used to manipulate types - and as described above some = synatic sugar is involved as well - and maybe they could be better = documented...but I'm not see where preventing the creation of either the = function or the type (whichever is created last) is a viable solution = and I'm not seeing that the current rule of using the implied type cast = function first is necessarily wrong. =20 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. =20 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"...? =20 Not that I could fix this even if I wanted to but the effort compared to = the number of complaints is not favorable to any change being = forthcoming. That includes documentation though that is more likely if = someone even puts forth a rough suggestion for what such an improvement = would look like. =20 David J. =20 ------=_NextPart_000_03F9_01D076CC.BFE18BE0 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable

I figured it had something to do with array types, given the error, but = still feel like creating the function, when it cannot be called, is an = error. I would appreciate getting an error similar to the one you = described instead of one later when attempting to call the function = since I would have saved me a couple of hours of debugging. I would = appreciate it if the documentation contained some hint that = type-conversion functions were automatically created by prepending an = underscore. (I don=E2=80=99t know how I would have found that nugget = without a better error message but still feel it is = missing.)

 

I also tried the quoted-identifier trick and was equally surprised it = didn=E2=80=99t work and then on reflection relieved that it = didn=E2=80=99t either.

 

We have solved the problem by changing our naming convention, given the = usual momentum on projects like this I don=E2=80=99t expect it to be = changed, but better documentation and an better error would be = appreciated.

 

From:<= /b> = David G. Johnston [mailto:david.g.johnston@gmail.com]
Sent: = Tuesday, April 14, 2015 3:55 PM
To: = dwayne.towell@gmail.com
Cc: = pgsql-bugs@postgresql.org
Subject: Re: [BUGS] BUG #13053: type = names pollute function name space

 

On Tue, = Apr 14, 2015 at 2:24 PM, <dwayne.towell@gmail.com> = wrote:

The following bug has been logged on the = website:

Bug reference:      13053
Logged = by:          Dwayne Towell
Email = address:      dwayne.towell@gmail.com
Po= stgreSQL version: 9.2.10
Operating system:  =  CentOS
Description:

The following:

=E2=80=8B=E2=80=8B

CREATE TYPE x AS (id int);
CREATE = FUNCTION _x(text) RETURNS SETOF x AS $$ SELECT 1 WHERE $1=3D'hi'; = $$
LANGUAGE SQL;
SELECT = _x('hi');

produces:

ERROR:  array value must start = with "{" or dimension information
LINE 1: SELECT = _x('hi');

Which seems wrong. Creating a type named 'x' should not = preempt my function
by finding an auto created(?) conversion(?) = function.

 

=E2=80=8BTo be more explicit = about what is happening here=E2=80=8B:

 

It is = finding the auto-magically created type "array x" aka: = "x[]=E2=80=8B".  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.

 

I'll admit it seems odd but I'd = chalk this up to system oddity and move on.  What is the solution = you are looking for anyway?

 

I'm sure there are more = surprises relating to types and functions since functions are used to = manipulate types - and as described above some synatic sugar is involved = as well - and maybe they could be better documented...but I'm not see = where preventing the creation of either the function or the type = (whichever is created last) is a viable solution and I'm not seeing that = the current rule of using the implied type cast function first is = necessarily wrong.

 

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.

 

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"...?

 

Not that I could fix this even = if I wanted to but the effort compared to the number of complaints is = not favorable to any change being forthcoming.  That includes = documentation though that is more likely if someone even puts forth a = rough suggestion for what such an improvement would look = like.

 

David = J.

 

------=_NextPart_000_03F9_01D076CC.BFE18BE0--