pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Overloading functions that are used by operators.
11+ messages / 4 participants
[nested] [flat]

* Overloading functions that are used by operators.
@ 2003-07-08 20:00 Donald Fraser <demolish@cwgsy.net>
  2003-07-08 21:05 ` Re: Overloading functions that are used by operators. Andreas Pflug <pgadmin@pse-consulting.de>
  0 siblings, 1 reply; 11+ messages in thread

From: Donald Fraser @ 2003-07-08 20:00 UTC (permalink / raw)
  To: pgsql-admin; +Cc: [pgADMIN] <pgadmin-support@postgresql.org>

I have a question regarding operators which are causing problems with the new pgAdmin III software being developed and my database.
The problem has been discussed in depth with the pgAdmin III development team and they have not been able to resolve the issue and suggested that I have either done something that I shouldn't have of or that there is a possible bug with postgresql.

Background information:
I have my own data type ('citext') that uses many of the built-in system functions based on the fact that the storage is identical to the data type 'text'.
For example I have overloaded the function 'textcat' and the definition I have used is:
CREATE FUNCTION pg_catalog.textcat(citext, citext) RETURNS citext AS 'textcat' LANGUAGE 'internal' IMMUTABLE STRICT;
When you view the functions via the pg_proc table you will see that there are two functions with 'textcat' in the column pg_proc.proname.
I have been using the database for over a year and had no reported problems with using the operator || on data types 'text', 'varchar', 'bpchar' or calling the overloaded function 'textcat(citext, citext)'.

First question:
Am I allowed to overload functions, for example the 'textcat' function, when they are being used by system operators?

If the answer is no then read no further - the problem is mine and I will have to work around it.

The system has at least three operators such as:
||(text,text)
||(varchar, text)
||(bpchar, text)
All use the function 'textcat'.

Now the new pgAdmin III software interrogates the pg_operator table to extract as much information as possible about the operators.
They are using the following SQL statement to retrieve the information that they want.

SELECT op.oid, op.oprname, pg_get_userbyid(op.oprowner) as opowner, op.oprkind, op.oprcanhash, 
op.oprleft, op.oprright, 
lt.typname as lefttype, 
rt.typname as righttype, 
et.typname as resulttype, 
co.oprname as compop, 
ne.oprname as negop, 
lso.oprname as leftsortop, 
rso.oprname as rightsortop, 
lco.oprname as lscmpop, 
gco.oprname as gtcmpop, 
po.proname as operproc, 
pj.proname as joinproc, 
pr.proname as restrproc, 
description 
FROM pg_operator op 
JOIN pg_type lt ON lt.oid=op.oprleft 
JOIN pg_type rt ON rt.oid=op.oprright 
JOIN pg_type et on et.oid=op.oprresult 
LEFT OUTER JOIN pg_operator co ON co.oid=op.oprcom 
LEFT OUTER JOIN pg_operator ne ON ne.oid=op.oprnegate 
LEFT OUTER JOIN pg_operator lso ON lso.oid=op.oprlsortop 
LEFT OUTER JOIN pg_operator rso ON rso.oid=op.oprrsortop 
LEFT OUTER JOIN pg_operator lco ON lco.oid=op.oprltcmpop 
LEFT OUTER JOIN pg_operator gco ON gco.oid=op.oprgtcmpop 
JOIN pg_proc po ON po.oid=op.oprcode 
LEFT OUTER JOIN pg_proc pr ON pr.oid=op.oprrest 
LEFT OUTER JOIN pg_proc pj ON pj.oid=op.oprjoin 
LEFT OUTER JOIN pg_description des ON des.objoid=op.oid 
WHERE op.oprnamespace = 2200::oid 
ORDER BY op.oprname

The offending part of this SQL statement is the join:
JOIN pg_proc po ON po.oid=op.oprcode

It produces the error message "ERROR: There is more than one procedure named textcat".
Investigation into this has shown that the type conversion of the column named pg_operator.oprcode to type oid is done by the function call to:
regprocin('textcat')

My question would be - what is the correct way to find the function's oid that this operator uses? But first read on in case it is not necessary...
It seems to me that the join statements they are using are unnecessary so long as the column pg_operator.oprcode has the identical name to its matching function that has its name defined by column pg_proc.proname, which seems to be the only data that they are using.

On a similar basis, do the columns named pg_operator.oprjoin and pg_operator.oprrest have identical names defined by the column pg_proc.proname for which they are also retrieving? If so then those corresponding joins are also unnecessarily.

Many thanks in advance,
regards
Donald Fraser.

^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Overloading functions that are used by operators.
  2003-07-08 20:00 Overloading functions that are used by operators. Donald Fraser <demolish@cwgsy.net>
@ 2003-07-08 21:05 ` Andreas Pflug <pgadmin@pse-consulting.de>
  0 siblings, 0 replies; 11+ messages in thread

From: Andreas Pflug @ 2003-07-08 21:05 UTC (permalink / raw)
  To: Donald Fraser <demolish@cwgsy.net>; +Cc: [pgADMIN] <pgadmin-support@postgresql.org>

Donald Fraser wrote:

> I have a question regarding operators which are causing problems with 
> the new pgAdmin III software being developed and my database.
> The problem has been discussed in depth with the pgAdmin III 
> development team and they have not been able to resolve the issue and 
> suggested that I have either done something that I shouldn't have of 
> or that there is a possible bug with postgresql.
>  
> Background information:
> I have my own data type ('citext') that uses many of the built-in 
> system functions based on the fact that the storage is identical to 
> the data type 'text'.
> For example I have overloaded the function 'textcat' and the 
> definition I have used is:
> CREATE FUNCTION pg_catalog.textcat(citext, citext) RETURNS citext AS 
> 'textcat' LANGUAGE 'internal' IMMUTABLE STRICT;
> When you view the functions via the pg_proc table you will see that 
> there are two functions with 'textcat' in the column pg_proc.proname.
> I have been using the database for over a year and had no reported 
> problems with using the operator || on data types 'text', 'varchar', 
> 'bpchar' or calling the overloaded function 'textcat(citext, citext)'.
>  
> First question:
> Am I allowed to overload functions, for example the 
> 'textcat' function, when they are being used by system operators?
>  
> If the answer is no then read no further - the problem is mine and I 
> will have to work around it.
>  
> The system has at least three operators such as:
> ||(text,text)
> ||(varchar, text)
> ||(bpchar, text)
> All use the function 'textcat'.
>  
> Now the new pgAdmin III software interrogates the pg_operator table to 
> extract as much information as possible about the operators.
> They are using the following SQL statement to retrieve the information 
> that they want.
>  
> SELECT op.oid, op.oprname, pg_get_userbyid(op.oprowner) as opowner, 
> op.oprkind, op.oprcanhash,
> op.oprleft, op.oprright,
> lt.typname as lefttype,
> rt.typname as righttype,
> et.typname as resulttype,
> co.oprname as compop,
> ne.oprname as negop,
> lso.oprname as leftsortop,
> rso.oprname as rightsortop,
> lco.oprname as lscmpop,
> gco.oprname as gtcmpop,
> po.proname as operproc,
> pj.proname as joinproc,
> pr.proname as restrproc,
> description
> FROM pg_operator op
> JOIN pg_type lt ON lt.oid=op.oprleft
> JOIN pg_type rt ON rt.oid=op.oprright
> JOIN pg_type et on et.oid=op.oprresult
> LEFT OUTER JOIN pg_operator co ON co.oid=op.oprcom
> LEFT OUTER JOIN pg_operator ne ON ne.oid=op.oprnegate
> LEFT OUTER JOIN pg_operator lso ON lso.oid=op.oprlsortop
> LEFT OUTER JOIN pg_operator rso ON rso.oid=op.oprrsortop
> LEFT OUTER JOIN pg_operator lco ON lco.oid=op.oprltcmpop
> LEFT OUTER JOIN pg_operator gco ON gco.oid=op.oprgtcmpop
> JOIN pg_proc po ON po.oid=op.oprcode
> LEFT OUTER JOIN pg_proc pr ON pr.oid=op.oprrest
> LEFT OUTER JOIN pg_proc pj ON pj.oid=op.oprjoin
> LEFT OUTER JOIN pg_description des ON des.objoid=op.oid
> WHERE op.oprnamespace = 2200::oid
> ORDER BY op.oprname
>  
> The offending part of this SQL statement is the join:
> JOIN pg_proc po ON po.oid=op.oprcode
>  
> It produces the error message "ERROR: There is more than one procedure 
> named textcat".
> Investigation into this has shown that the type conversion of the 
> column named pg_operator.oprcode to type oid is done by the function 
> call to:
> regprocin('textcat')
> My question would be - what is the correct way to find the function's 
> oid that this operator uses? But first read on in case it is not 
> necessary...
> It seems to me that the join statements they are using are unnecessary 
> so long as the column pg_operator.oprcode has the identical name to 
> its matching function that has its name defined by column 
> pg_proc.proname, which seems to be the only data that they are using.
>  
> On a similar basis, do the columns named pg_operator.oprjoin and 
> pg_operator.oprrest have identical names defined by the column 
> pg_proc.proname for which they are also retrieving? If so then those 
> corresponding joins are also unnecessarily.
>  


Donald,

we discussed that this should go to pgsql-bugs, not any admin list. 
While there might be some question if joining pg_proc to pg_type is 
necessary for pgAdmin3, but it's certainly legal to query which pg_proc 
is used for a type.
The underlying question for your case is whether it's allowed to create 
overloaded functions of a function that's used for a type.
regprocin will not like this, so CREATE TYPE should deny creation if 
input or output function isn't unique by name.

Regards,
Andreas




^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Overloading functions that are used by operators.
@ 2003-07-08 20:12 Dave Page <dpage@vale-housing.co.uk>
  2003-07-08 20:19 ` Re: Overloading functions that are used by operators. Donald Fraser <demolish@cwgsy.net>
  0 siblings, 1 reply; 11+ messages in thread

From: Dave Page @ 2003-07-08 20:12 UTC (permalink / raw)
  To: Donald Fraser <demolish@cwgsy.net>; pgsql-admin; +Cc: [pgADMIN] <pgadmin-support@postgresql.org>

 

	-----Original Message-----
	From: Donald Fraser [mailto:demolish@cwgsy.net] 
	Sent: 08 July 2003 21:00
	To: [ADMIN]
	Cc: [pgADMIN]
	Subject: [pgadmin-support] Overloading functions that are used
by operators.
	
	
	I have a question regarding operators which are causing problems
with the new pgAdmin III software being developed and my database.
	The problem has been discussed in depth with the pgAdmin III
development team and they have not been able to resolve the issue and
suggested that I have either done something that I shouldn't have of or
that there is a possible bug with postgresql. 
	 

Where was it discussed in depth? The last I heard was that Andreas was
going to look into it.
 
I will see if I can reproduce the problem myself.
 
Regards, Dave.

^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Overloading functions that are used by operators.
  2003-07-08 20:12 Re: Overloading functions that are used by operators. Dave Page <dpage@vale-housing.co.uk>
@ 2003-07-08 20:19 ` Donald Fraser <demolish@cwgsy.net>
  0 siblings, 0 replies; 11+ messages in thread

From: Donald Fraser @ 2003-07-08 20:19 UTC (permalink / raw)
  To: [pgADMIN] <pgadmin-support@postgresql.org>

MessageSorry, I or Andreas can forward you the discussion we had, it didn't get published which I guess it should have (whoops).
(I always get fooled by reply as it doesn't default to the mailing group)

Regards
Donald


  ----- Original Message ----- 
  From: Dave Page 
  To: Donald Fraser ; [ADMIN] 
  Cc: [pgADMIN] 
  Sent: Tuesday, July 08, 2003 9:12 PM
  Subject: RE: [pgadmin-support] Overloading functions that are used by operators.



    -----Original Message-----
    From: Donald Fraser [mailto:demolish@cwgsy.net] 
    Sent: 08 July 2003 21:00
    To: [ADMIN]
    Cc: [pgADMIN]
    Subject: [pgadmin-support] Overloading functions that are used by operators.


    I have a question regarding operators which are causing problems with the new pgAdmin III software being developed and my database.
    The problem has been discussed in depth with the pgAdmin III development team and they have not been able to resolve the issue and suggested that I have either done something that I shouldn't have of or that there is a possible bug with postgresql. 

  Where was it discussed in depth? The last I heard was that Andreas was going to look into it.

  I will see if I can reproduce the problem myself.

  Regards, Dave.

^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Overloading functions that are used by operators.
@ 2003-07-08 20:49 Dave Page <dpage@vale-housing.co.uk>
  2003-07-09 10:03 ` Re: Overloading functions that are used by operators. Donald Fraser <demolish@cwgsy.net>
  2003-07-10 15:37 ` Re: [ADMIN] Overloading functions that are used by operators. Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 11+ messages in thread

From: Dave Page @ 2003-07-08 20:49 UTC (permalink / raw)
  To: Donald Fraser <demolish@cwgsy.net>; +Cc: pgsql-admin; [pgADMIN] <pgadmin-support@postgresql.org>

Ahh, thanks. Was just looking at that.
 
Well I always thought you could overload functions in this way, however
with 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
know you can - there's one of mine in PostgreSQL 7.3!). I wonder if in
this case the system knows that it can implicitly cast the arguments of
one function to the other and hence the error is given?
 
Would this be the case for your citext datatype?
 
Regards, Dave.

	-----Original Message-----
	From: Donald Fraser [mailto:demolish@cwgsy.net] 
	Sent: 08 July 2003 21:27
	To: Dave Page
	Subject: Re: [pgadmin-support] Overloading functions that are
used by operators.
	
	
	Hi Dave,
	if you want an easy way to reproduce it do the following:
	 
	CREATE FUNCTION pg_catalog.textcat(varchar, text) RETURNS text
AS 'textcat' LANGUAGE 'internal' IMMUTABLE STRICT;
	This wouldn't normally be necessary as we have type casting that
will handle it and or operators but anyway that's beside the point...
	 
	Either the above statement is illegal or you have to find a
different method for locating the function name associated with an
operator.
	That's the crux of the matter.
	 
	Regards
	Donald Fraser.

		----- Original Message ----- 
		From: Dave Page <mailto:dpage@vale-housing.co.uk>  
		To: Donald Fraser <mailto:demolish@cwgsy.net>  ; [ADMIN]
<mailto:pgsql-admin@postgresql.org>  
		Cc: [pgADMIN] <mailto:pgadmin-support@postgresql.org>  
		Sent: Tuesday, July 08, 2003 9:12 PM
		Subject: RE: [pgadmin-support] Overloading functions
that are used by operators.

		 

			-----Original Message-----
			From: Donald Fraser [mailto:demolish@cwgsy.net] 
			Sent: 08 July 2003 21:00
			To: [ADMIN]
			Cc: [pgADMIN]
			Subject: [pgadmin-support] Overloading functions
that are used by operators.
			
			
			I have a question regarding operators which are
causing problems with the new pgAdmin III software being developed and
my database.
			The problem has been discussed in depth with the
pgAdmin III development team and they have not been able to resolve the
issue and suggested that I have either done something that I shouldn't
have of or that there is a possible bug with postgresql. 
			 

		Where was it discussed in depth? The last I heard was
that Andreas was going to look into it.
		 
		I will see if I can reproduce the problem myself.
		 
		Regards, Dave.

^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Overloading functions that are used by operators.
  2003-07-08 20:49 Re: Overloading functions that are used by operators. Dave Page <dpage@vale-housing.co.uk>
@ 2003-07-09 10:03 ` Donald Fraser <demolish@cwgsy.net>
  1 sibling, 0 replies; 11+ messages in thread

From: Donald Fraser @ 2003-07-09 10:03 UTC (permalink / raw)
  To: [pgADMIN] <pgadmin-support@postgresql.org>

Message
  ----- Original Message ----- 
  From: Dave Page 
  To: Donald Fraser 
  Cc: [ADMIN] ; [pgADMIN] 
  Sent: Tuesday, July 08, 2003 9:49 PM
  Subject: RE: [pgadmin-support] Overloading functions that are used by operators.


  Ahh, thanks. Was just looking at that.

  Well I always thought you could overload functions in this way, however with 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 know you can - there's one of mine in PostgreSQL 7.3!). I wonder if in this case the system knows that it can implicitly cast the arguments of one function 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 even though they are partially involved, my custom type has nothing to do with 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. 

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 might 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 that it is possible simply because postgresql allows and supports function overloading.

Everything in postgres will still work, even the operators for the data types 'text', 'varchar' and 'bpchar'. ('textcat' is used as operators for ||)
Function overloading is definitely allowed because you can look in the pg_catalog.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 function, 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 assumption 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 function to decide which function to call - they also have all of the information about the arguments. That is how an operator knows exactly which function to call. Hence pg_operator.oprcode is not the sole means for deciding which 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.oprcode, pg_operator.oprrest and pg_operator.oprjoin columns.
For example:
JOIN pg_proc po ON po.oid=op.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. 
For example if you do: SELECT regprocin('abs') you get the same sort of error message that we are experiencing: "ERROR: There is more than one procedure 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 = abs, LEFTARG = int4);
I think you can see where I was going with this example. 'abs' is a function that already exists and is already overloaded many times by the system, no additional data types necessary or any additional function overloading. Unfortunately 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 anywhere - 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.

^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: [ADMIN] Overloading functions that are used by operators.
  2003-07-08 20:49 Re: Overloading functions that are used by operators. Dave Page <dpage@vale-housing.co.uk>
@ 2003-07-10 15:37 ` Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 0 replies; 11+ messages in thread

From: Tom Lane @ 2003-07-10 15:37 UTC (permalink / raw)
  To: Dave Page <dpage@vale-housing.co.uk>; +Cc: Donald Fraser <demolish@cwgsy.net>; pgsql-admin; [pgADMIN] <pgadmin-support@postgresql.org>

"Dave Page" <dpage@vale-housing.co.uk> writes:
> Well I always thought you could overload functions in this way, however
> with your example below, although it creates it OK, PostgreSQL (not
> pgAdmin) gives the error 'ERROR: There is more than one function named
> textcat'.

I see no such error here ...

regression=# create function pg_catalog.textcat(varchar,text)
regression-# returns text as 'textcat' language 'internal';
CREATE FUNCTION


			regards, tom lane



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: [ADMIN] Overloading functions that are used by operators.
@ 2003-07-10 15:52 Dave Page <dpage@vale-housing.co.uk>
  2003-07-10 16:06 ` Re: [ADMIN] Overloading functions that are used by operators. Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 11+ messages in thread

From: Dave Page @ 2003-07-10 15:52 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Donald Fraser <demolish@cwgsy.net>; pgsql-admin; [pgADMIN] <pgadmin-support@postgresql.org>



> -----Original Message-----
> From: Tom Lane [mailto:tgl@sss.pgh.pa.us] 
> Sent: 10 July 2003 16:38
> To: Dave Page
> Cc: Donald Fraser; [ADMIN]; [pgADMIN]
> Subject: Re: [ADMIN] [pgadmin-support] Overloading functions 
> that are used by operators. 
> 
> 
> "Dave Page" <dpage@vale-housing.co.uk> writes:
> > Well I always thought you could overload functions in this way, 
> > however with your example below, although it creates it OK, 
> PostgreSQL 
> > (not
> > pgAdmin) gives the error 'ERROR: There is more than one 
> function named
> > textcat'.
> 
> I see no such error here ...
> 
> regression=# create function pg_catalog.textcat(varchar,text) 
> regression-# returns text as 'textcat' language 'internal'; 
> CREATE FUNCTION

Andreas (Pflug) reckons it's gone in 7.4, but in 7.3.2 I see:

postgresql=# create function pg_catalog.textcat(varchar,text)
postgresql-# returns text as 'textcat' language 'internal';
CREATE FUNCTION
postgresql=# SELECT op.oid, op.oprname, pg_get_userbyid(op.oprowner) as
opowner, op.oprkind, op.oprcanhash,
postgresql-#                op.oprleft, op.oprright, lt.typname as
lefttype, rt.typname as righttype, et.typname as resulttype,
postgresql-#                co.oprname as compop, ne.oprname as negop,
lso.oprname as leftsortop, rso.oprname as rightsortop,
postgresql-#                lco.oprname as lscmpop, gco.oprname as
gtcmpop,
postgresql-#                po.proname as operproc, pj.proname as
joinproc, pr.proname as restrproc, description
postgresql-#           FROM pg_operator op
postgresql-#           LEFT OUTER JOIN pg_type lt ON lt.oid=op.oprleft
postgresql-#           LEFT OUTER JOIN pg_type rt ON rt.oid=op.oprright
postgresql-#           JOIN pg_type et on et.oid=op.oprresult
postgresql-#           LEFT OUTER JOIN pg_operator co ON
co.oid=op.oprcom
postgresql-#           LEFT OUTER JOIN pg_operator ne ON
ne.oid=op.oprnegate
postgresql-#           LEFT OUTER JOIN pg_operator lso ON
lso.oid=op.oprlsortop
postgresql-#           LEFT OUTER JOIN pg_operator rso ON
rso.oid=op.oprrsortop
postgresql-#           LEFT OUTER JOIN pg_operator lco ON
lco.oid=op.oprltcmpop
postgresql-#           LEFT OUTER JOIN pg_operator gco ON
gco.oid=op.oprgtcmpop
postgresql-#           JOIN pg_proc po ON po.oid=op.oprcode
postgresql-#           LEFT OUTER JOIN pg_proc pr ON pr.oid=op.oprrest
postgresql-#           LEFT OUTER JOIN pg_proc pj ON pj.oid=op.oprjoin
postgresql-#           LEFT OUTER JOIN pg_description des ON
des.objoid=op.oid;
ERROR:  There is more than one procedure named textcat

Dropping the extra function, or changing the query a little fixes it:

postgresql=# SELECT op.oid, op.oprname, pg_get_userbyid(op.oprowner) as
opowner, op.oprkind, op.oprcanhash,
postgresql-#                op.oprleft, op.oprright, lt.typname as
lefttype, rt.typname as righttype, et.typname as resulttype,
postgresql-#                co.oprname as compop, ne.oprname as negop,
lso.oprname as leftsortop, rso.oprname as rightsortop,
postgresql-#                lco.oprname as lscmpop, gco.oprname as
gtcmpop,
postgresql-#                op.oprcode as operproc, op.oprjoin as
joinproc, op.oprrest as restrproc, description
postgresql-#           FROM pg_operator op
postgresql-#           LEFT OUTER JOIN pg_type lt ON lt.oid=op.oprleft
postgresql-#           LEFT OUTER JOIN pg_type rt ON rt.oid=op.oprright
postgresql-#           JOIN pg_type et on et.oid=op.oprresult
postgresql-#           LEFT OUTER JOIN pg_operator co ON
co.oid=op.oprcom
postgresql-#           LEFT OUTER JOIN pg_operator ne ON
ne.oid=op.oprnegate
postgresql-#           LEFT OUTER JOIN pg_operator lso ON
lso.oid=op.oprlsortop
postgresql-#           LEFT OUTER JOIN pg_operator rso ON
rso.oid=op.oprrsortop
postgresql-#           LEFT OUTER JOIN pg_operator lco ON
lco.oid=op.oprltcmpop
postgresql-#           LEFT OUTER JOIN pg_operator gco ON
gco.oid=op.oprgtcmpop
postgresql-#           LEFT OUTER JOIN pg_description des ON
des.objoid=op.oid;
 oid  | oprname | opowner  | oprkind | oprcanhash | oprleft | oprright |
lefttype ....

Regards, Dave.



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: [ADMIN] Overloading functions that are used by operators.
  2003-07-10 15:52 Re: [ADMIN] Overloading functions that are used by operators. Dave Page <dpage@vale-housing.co.uk>
@ 2003-07-10 16:06 ` Tom Lane <tgl@sss.pgh.pa.us>
  2003-07-10 17:10   ` Re: [ADMIN] Overloading functions that are used by operators. Donald Fraser <demolish@cwgsy.net>
  0 siblings, 1 reply; 11+ messages in thread

From: Tom Lane @ 2003-07-10 16:06 UTC (permalink / raw)
  To: Dave Page <dpage@vale-housing.co.uk>; +Cc: Donald Fraser <demolish@cwgsy.net>; pgsql-admin; [pgADMIN] <pgadmin-support@postgresql.org>

"Dave Page" <dpage@vale-housing.co.uk> writes:
>> I see no such error here ...
>> 
>> regression=# create function pg_catalog.textcat(varchar,text) 
>> regression-# returns text as 'textcat' language 'internal'; 
>> CREATE FUNCTION

> Andreas (Pflug) reckons it's gone in 7.4, but in 7.3.2 I see:
> [ complicated query ]

Oh.  I'll bet you're running into the regproc-reverse-conversion
problem.  'textcat' is one of the histogram values appearing in pg_stats
for pg_operator.oprcode, right?  The error comes when the planner tries
to convert that string back to OID form.  We fixed this in 7.4 by
modifying the way that pg_statistic stores data values, so that no
conversion needs to occur.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: [ADMIN] Overloading functions that are used by operators.
  2003-07-10 15:52 Re: [ADMIN] Overloading functions that are used by operators. Dave Page <dpage@vale-housing.co.uk>
  2003-07-10 16:06 ` Re: [ADMIN] Overloading functions that are used by operators. Tom Lane <tgl@sss.pgh.pa.us>
@ 2003-07-10 17:10   ` Donald Fraser <demolish@cwgsy.net>
  0 siblings, 0 replies; 11+ messages in thread

From: Donald Fraser @ 2003-07-10 17:10 UTC (permalink / raw)
  To: [pgADMIN] <pgadmin-support@postgresql.org>


----- Original Message -----
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "Dave Page" <dpage@vale-housing.co.uk>
Cc: "Donald Fraser" <demolish@cwgsy.net>; "[ADMIN]"
<pgsql-admin@postgresql.org>; "[pgADMIN]" <pgadmin-support@postgresql.org>
Sent: Thursday, July 10, 2003 5:06 PM
Subject: Re: [ADMIN] [pgadmin-support] Overloading functions that are used by
operators.


> "Dave Page" <dpage@vale-housing.co.uk> writes:
> >> I see no such error here ...
> >>
> >> regression=# create function pg_catalog.textcat(varchar,text)
> >> regression-# returns text as 'textcat' language 'internal';
> >> CREATE FUNCTION
>
> > Andreas (Pflug) reckons it's gone in 7.4, but in 7.3.2 I see:
> > [ complicated query ]
>
> Oh.  I'll bet you're running into the regproc-reverse-conversion
> problem.  'textcat' is one of the histogram values appearing in pg_stats
> for pg_operator.oprcode, right?  The error comes when the planner tries
> to convert that string back to OID form.  We fixed this in 7.4 by
> modifying the way that pg_statistic stores data values, so that no
> conversion needs to occur.
>
> regards, tom lane

Well there you go then... trust me to run into some obscure bug!

I kept asking how it was possible to get the function oid via just the function
name, and nobody pointed out what the undelying data type of
pg_operator.oprcode is.

In that case you can use the subselect approach that I originally suggested and
you will find that it actually works.
That is replace column 'po.proname as operproc,' with '(SELECT po.proname FROM
pg_proc po WHERE po.oid=op.oprcode) as operproc,' and obviously remove the
associated join statment and repeat this for the other two columns: pj.proname
as joinproc and pr.proname as restrproc.

Regards
Donald Fraser.




^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: [ADMIN] Overloading functions that are used by operators.
@ 2003-07-10 16:30 Dave Page <dpage@vale-housing.co.uk>
  0 siblings, 0 replies; 11+ messages in thread

From: Dave Page @ 2003-07-10 16:30 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Donald Fraser <demolish@cwgsy.net>; pgsql-admin; [pgADMIN] <pgadmin-support@postgresql.org>



> -----Original Message-----
> From: Tom Lane [mailto:tgl@sss.pgh.pa.us] 
> Sent: 10 July 2003 17:07
> To: Dave Page
> Cc: Donald Fraser; [ADMIN]; [pgADMIN]
> Subject: Re: [ADMIN] [pgadmin-support] Overloading functions 
> that are used by operators. 
> 
> 
> "Dave Page" <dpage@vale-housing.co.uk> writes:
> >> I see no such error here ...
> >> 
> >> regression=# create function pg_catalog.textcat(varchar,text)
> >> regression-# returns text as 'textcat' language 'internal'; 
> >> CREATE FUNCTION
> 
> > Andreas (Pflug) reckons it's gone in 7.4, but in 7.3.2 I see: [ 
> > complicated query ]
> 
> Oh.  I'll bet you're running into the 
> regproc-reverse-conversion problem.  'textcat' is one of the 
> histogram values appearing in pg_stats for 
> pg_operator.oprcode, right?  The error comes when the planner 
> tries to convert that string back to OID form.  We fixed this 
> in 7.4 by modifying the way that pg_statistic stores data 
> values, so that no conversion needs to occur.

Yeah, that sounds like it. The simplified query stops the conversion to
oid by just returning the function name rather than joining with
pg_proc. Works just as well for us I think and simplifies the query
somewhat.

Thanks for looking.

Regards, Dave.



^ permalink  raw  reply  [nested|flat] 11+ messages in thread


end of thread, other threads:[~2003-07-10 17:10 UTC | newest]

Thread overview: 11+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-07-08 20:00 Overloading functions that are used by operators. Donald Fraser <demolish@cwgsy.net>
2003-07-08 21:05 ` Andreas Pflug <pgadmin@pse-consulting.de>
2003-07-08 20:12 Re: Overloading functions that are used by operators. Dave Page <dpage@vale-housing.co.uk>
2003-07-08 20:19 ` Donald Fraser <demolish@cwgsy.net>
2003-07-08 20:49 Re: Overloading functions that are used by operators. Dave Page <dpage@vale-housing.co.uk>
2003-07-09 10:03 ` Donald Fraser <demolish@cwgsy.net>
2003-07-10 15:37 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-07-10 15:52 Re: [ADMIN] Overloading functions that are used by operators. Dave Page <dpage@vale-housing.co.uk>
2003-07-10 16:06 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-07-10 17:10   ` Donald Fraser <demolish@cwgsy.net>
2003-07-10 16:30 Re: [ADMIN] Overloading functions that are used by operators. Dave Page <dpage@vale-housing.co.uk>

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