Re: Namespace issues

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Don Y <pgsql(at)DakotaCom(dot)Net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Namespace issues
Date: 2006-05-16 17:34:12
Message-ID: 20060516173412.GH976@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, May 16, 2006 at 10:29:27AM -0700, Don Y wrote:
> Given a user defined type foo...
> I've created several casts to/from foo and built-in types.
> I had adopted a naming convention of:
> baz foo_to_baz(foo);
> foo foo_from_baz(baz);
>
> But:

<snip>

> I don't see how I can do this in my declarations. E.g.,
> if I have
> baz = {int4, text, float8, ...}
> then I end up with several (C) functions all named foo()
> but each taking a different argument type (baz). Since
> C doesn't support more than a single namespace for functions,
> this just won't work.
>
> What am I failing to see, here?

That the name of the function in C doesn't have to be the same as the
name of the function in SQL. You can even define many SQL functions
that all refer to the same C function.

So in your C file yo call them:

cast_foo_to_baz()

and in the SQL you declare as just:

baz()

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Kenneth Downs 2006-05-16 17:40:44 Re: best practice in upgrading db structure
Previous Message Don Y 2006-05-16 17:30:16 Re: error handling in cast functions for user defined types