X-Original-To: pgadmin-support-postgresql.org@localhost.postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 9F8D6B438AC for ; Wed, 9 Jul 2003 10:02:00 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 26312-08 for ; Wed, 9 Jul 2003 07:01:36 -0300 (ADT) Received: from gsy_sbs_1.cisx.com (unknown [213.133.202.58]) by svr1.postgresql.org (Postfix) with ESMTP id 6797FB43183 for ; Wed, 9 Jul 2003 07:01:33 -0300 (ADT) Received: from DEMOLITION ([192.168.100.22]) by gsy_sbs_1.cisx.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2650.21) id 3RZZCSQG; Wed, 9 Jul 2003 10:52:43 +0100 Message-ID: <004d01c34601$6c1c4710$1664a8c0@DEMOLITION> From: "Donald Fraser" To: "[pgADMIN]" References: <03AF4E498C591348A42FC93DEA9661B83AF16D@mail.vale-housing.co.uk> Subject: Re: Overloading functions that are used by operators. Date: Wed, 9 Jul 2003 11:03:56 +0100 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_004A_01C34609.CAD061D0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4927.1200 X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4927.1200 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/77 X-Sequence-Number: 1677 This is a multi-part message in MIME format. ------=_NextPart_000_004A_01C34609.CAD061D0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Message ----- Original Message -----=20 From: Dave Page=20 To: Donald Fraser=20 Cc: [ADMIN] ; [pgADMIN]=20 Sent: Tuesday, July 08, 2003 9:49 PM Subject: RE: [pgadmin-support] Overloading functions that are used by ope= rators. Ahh, thanks. Was just looking at that. Well I always thought you could overload functions in this way, however w= ith your example below, although it creates it OK, PostgreSQL (not pgAdmin)= gives the error 'ERROR: There is more than one function named textcat'. As I said, I'm pretty sure that you can overload functions (in fact I kno= w you can - there's one of mine in PostgreSQL 7.3!). I wonder if in this ca= se the system knows that it can implicitly cast the arguments of one functi= on to the other and hence the error is given? Would this be the case for your citext datatype? Regards, Dave. Hi Dave and Andreas, sorry about all the confusion I've created. Hopefully this email will clear everything up as there are only two things = at issue here - operators and function overloading, leave data types out ev= en though they are partially involved, my custom type has nothing to do wit= h it. I have removed my data type all together and can still produce the problem = by simply overloading any function that is also used by an operator. Hence = the 'textcat' example I gave previously.=20 Here is another example that doesn't use any custom data types. Lets say I = wanted to concatenate binary data together and so I define my own function = in a 'C' module named 'bincat.so'. The function definition in postgres migh= t be: CREATE FUNCTION pg_catalog.textcat(bytea, bytea) RETURNS bytea AS 'bincat',= 'bincat.so' LANGUAGE 'c' IMMUTABLE STRICT; Now forget why you would give it a name such as 'textcat', the thing it tha= t it is possible simply because postgresql allows and supports function ove= rloading. Everything in postgres will still work, even the operators for the data typ= es 'text', 'varchar' and 'bpchar'. ('textcat' is used as operators for ||) Function overloading is definitely allowed because you can look in the pg_c= atalog.pg_proc table for yourselves and see many internal functions such as= 'abs' which are overloaded many times. Now back to pgAdmin III: now that I have created this new overloaded functi= on, pgAdmin III will fail when it trys to populate the "Operators" section = of the public schema. Why - because I now have two functions named 'textcat= ', which is perfectly legal but pgAdmin is making an assumption. The assump= tion is that the name of the function associated to an operator defined by = pg_operator.oprcode is unique. Operators don't just use the name of the fun= ction to decide which function to call - they also have all of the informat= ion about the arguments. That is how an operator knows exactly which functi= on to call. Hence pg_operator.oprcode is not the sole means for deciding wh= ich function will be called, which is what pgAdmin III is assuming. The offending SQL in pgAdmin III are the joins that use the pg_operator.opr= code, pg_operator.oprrest and pg_operator.oprjoin columns. For example: JOIN pg_proc po ON po.oid=3Dop.oprcode postgresql has to convert the op.oprcode to an oid via a function call to "= regprocin(op.oprcode)". The function "regprocin" can only do this if the function name passed to it= is unique within the table column pg_catalog.proname, otherwise it doesn't= know which function oid it should return.=20 For example if you do: SELECT regprocin('abs') you get the same sort of err= or message that we are experiencing: "ERROR: There is more than one procedu= re named abs" I had another idea that I thought would explain things much easier for you,= but unfortunately it exposes yet another bug. Try this: CREATE OPERATOR !@ (PROCEDURE =3D abs, LEFTARG =3D int4); I think you can see where I was going with this example. 'abs' is a functio= n that already exists and is already overloaded many times by the system, n= o additional data types necessary or any additional function overloading. U= nfortunately I don't get the error I was expecting pgAdmin III to display, = but that's probably because pgAdmin III is not seeing this operator anywher= e - not in 'public' or 'pg_catalog' schemas. I also noticed that in pg_catalog using pgAdmin II there are 643 operators = yet pgAdmin III reports only 596? I hope that clears things up for you and that I haven't gone down the wrong= road yet again. Regards Donald Fraser. ------=_NextPart_000_004A_01C34609.CAD061D0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Message
 
----- Original Message -----
Fro= m:=20 Dave=20 Page
Cc: [ADMIN] ; [pgADMIN]
Sent: Tuesday, July 08, 2003 9:49= =20 PM
Subject: RE: [pgadmin-support]=20 Overloading functions that are used by operators.

Ahh,=20 thanks. Was just looking at that.
 
Well=20 I always thought you could overload functions in this way, however with y= our=20 example below, although it creates it OK, PostgreSQL (not pgAdmin) gives = the=20 error 'ERROR: There is more than one function named=20 textcat'.
 
As I=20 said, I'm pretty sure that you can overload functions (in fact I know you= can=20 - there's one of mine in PostgreSQL 7.3!). I wonder if in this case the s= ystem=20 knows that it can implicitly cast the arguments of one function to the ot= her=20 and hence the error is given?
 
Would this be the case for your citext datatype?
 
Regards, Dave.
 
Hi Dave and=20 Andreas,
sorry about=20 all the confusion I've created.
Hopefully=20 this email will clear everything up as there are only two things at is= sue=20 here - operators and function overloading, leave data types out even though= they=20 are partially involved, my custom type has nothing to do with=20 it.
I have=20 removed my data type all together and can still produce the problem by simp= ly=20 overloading any function that is also used by an operator. Hence the 'textc= at'=20 example I gave previously.
 
Here=20 is another example that doesn't use any custom data types. Lets say I= =20 wanted to concatenate binary data together and so I define my own function = in a=20 'C' module named 'bincat.so'. The function definition in postgres might=20 be:
CREATE FUNCTION pg_catalog.textcat(bytea, = bytea)=20 RETURNS bytea AS 'bincat', 'bincat.so' LANGUAGE 'c' IMMUTABLE=20 STRICT;
Now forget why you would give it a name&nb= sp;such=20 as 'textcat', the thing it that it is possible simply because postgres= ql=20 allows and supports function overloading.
 
Everything in postgres will still work, ev= en the=20 operators for the data types 'text', 'varchar' and 'bpchar'. ('textcat' is = used=20 as operators for ||)
Function overloading is definitely allowed= because=20 you can look in the pg_catalog.pg_proc table for yourselves and see many=20 internal functions such as 'abs' which are overloaded many=20 times.
 
Now back to=20 pgAdmin III: now that I have created this new overloaded function, pgAdmin = III=20 will fail when it trys to populate the "Operators" section of the public sc= hema.=20 Why - because I now have two functions named 'textcat', which is perfectly = legal=20 but pgAdmin is making an assumption. The assumption is that the name of the= =20 function associated to an operator defined by pg_operator.oprcode is unique= .=20 Operators don't just use the name of the function to decide which function = to=20 call - they also have all of the information about the arguments. That= is=20 how an operator knows exactly which function to call. Hence pg_operator.opr= code=20 is not the sole means for deciding which function will be called, whic= h is=20 what pgAdmin III is assuming.
 
The=20 offending SQL in pgAdmin III are the joins that use the=20 pg_operator.oprcode, pg_operator.oprrest and pg_operator.oprjoin=20 columns.
For=20 example:
JOIN pg_proc=20 po ON po.oid=3Dop.oprcode
postgresql=20 has to convert the op.oprcode to an oid via a function call to=20 "regprocin(op.oprcode)".
The function=20 "regprocin" can only do this if the function name passed to it is unique wi= thin=20 the table column pg_catalog.proname, otherwise it doesn't know which functi= on=20 oid it should return.
For example=20 if you do: SELECT regprocin('abs') you get the same sort of error message t= hat=20 we are experiencing: "ERROR: There is more than one procedure named=20 abs"
I had=20 another idea that I thought would explain things much easier for you, but= =20 unfortunately it exposes yet another bug.
Try=20 this:
CREATE=20 OPERATOR !@=20 (PROCEDURE =3D abs, LEFTARG =3D int4);
I think you can see where I was going wit= h this=20 example. 'abs' is a function that already exists and is already overloaded = many=20 times by the system, no additional data types necessary or any additional= =20 function overloading. Unfortunately I don't get the error I was expecting= =20 pgAdmin III to display, but that's probably because pgAdmin III is not seei= ng=20 this operator anywhere - not in 'public' or=20 'pg_catalog' schemas.
I also noticed that in pg_catalog using p= gAdmin II=20 there are 643 operators yet pgAdmin III reports only 596?
 
I hope that clears things up for you and = that I=20 haven't gone down the wrong road yet again.
 
Regards
Donald=20 Fraser.
------=_NextPart_000_004A_01C34609.CAD061D0--