Re: generic builtin functions

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: generic builtin functions
Date: 2005-11-10 19:37:34
Message-ID: 20051110193733.GJ19686@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Nov 10, 2005 at 01:15:07PM -0500, Tom Lane wrote:
> Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> > What I want to have is some builtin functions that can be used as the
> > input/output/cast/etc functions for each enum type.
>
> The hard part of that is going to be figuring out how to get the
> information to the functions about which enum type they're being invoked
> for. Output functions in particular are handed little except the data
> value itself.

For my taggedtypes module I simply created an output function for each
type, but they all referred to the same C function. The fmgr interface
does allow you to retreive your own OID, which allows you to search the
catalog to determine what type you were called with and/or need to
return. I actually built a little LRU cache for the
function-to-return-type lookup to avoid most of the overhead.

> Possibly the internal representation of an enum could be 8 bytes: 4
> bytes for type OID and 4 more for value. No doubt the mysql guys would
> rag on us for using too much disk space :-(. But if you did that then
> the generics would just be anyenum and done.

That's another way, but it is really worth the effort to make another any*
type. For arrays it's worth it because people assume you can make an
array of most things. But enums needs to be explicitly defined and how
many enums are you expecting anyway. Is pg_proc bloat an actual
concern?

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Joshua D. Drake 2005-11-10 20:23:46 Re: Obtaining a source tree from CVS
Previous Message Tom Lane 2005-11-10 19:25:15 Re: generic builtin functions