X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B561AD1B182 for ; Wed, 30 Jun 2004 10:47:58 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 72679-03 for ; Wed, 30 Jun 2004 13:47:58 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 83F2BD1B181 for ; Wed, 30 Jun 2004 10:47:54 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i5UDluoX008121; Wed, 30 Jun 2004 09:47:56 -0400 (EDT) To: Joe Conway Cc: pgsql-hackers@postgreSQL.org Subject: Implicit casting for || (was Re: grant execute on many functions) In-reply-to: <40E24C15.4040901@joeconway.com> References: <40E1E1A9.8080207@fastmail.fm> <40E1ECEF.5090007@joeconway.com> <3318.1088567114@sss.pgh.pa.us> <40E23F72.4000108@joeconway.com> <3843.1088570281@sss.pgh.pa.us> <40E24C15.4040901@joeconway.com> Comments: In-reply-to Joe Conway message dated "Tue, 29 Jun 2004 22:13:57 -0700" Date: Wed, 30 Jun 2004 09:47:56 -0400 Message-ID: <8120.1088603276@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/1000 X-Sequence-Number: 55550 [ moving thread to a more appropriate list ] Joe Conway writes: > Tom Lane wrote: >> select 'GRANT EXECUTE ON ' || 1142::regprocedure; >> ERROR: array value must start with "{" or dimension information >> >> BTW, it seems like there's something pretty broken here. How did >> arrays get into it? > regression=# \df array_append > List of functions > Result data type | Schema | Name | Argument data types > -------------------+------------+--------------+---------------------- > anyarray | pg_catalog | array_append | anyarray, anyelement > (1 row) > So the "||" operator sees (unknown, regprocedure), and make_op tries to > coerce the unknown literal to an array of regprocedure, which of course > fails. If instead the literal is explicitly cast: > select 'GRANT EXECUTE ON '::text || 1142::regprocedure; > ERROR: operator does not exist: text || regprocedure > HINT: No operator matches the given name and argument type(s). You may > need to add explicit type casts. > I'm not clear on how we can do better :(. Any suggestions? I'm not sure either, but I can't say that I like this interpretation. I did find that if there is an implicit coercion to text then the system will prefer a saner interpretation: regression=# select 'GRANT EXECUTE ON ' || 1142::regprocedure; ERROR: array value must start with "{" or dimension information regression=# create function text(regprocedure) returns text as ' regression'# begin regression'# return $1; regression'# end' language plpgsql stable strict; CREATE FUNCTION regression=# create cast (regprocedure as text) with function text(regprocedure) as implicit; CREATE CAST regression=# select 'GRANT EXECUTE ON ' || 1142::regprocedure; ?column? ----------------------------------------- GRANT EXECUTE ON date_mii(date,integer) (1 row) I'm worried though about how stable this choice is. I'm almost tempted to add a wart in the coercion routines to discourage matching "unknown" to "anyarray" ... regards, tom lane