Re: [HACKERS] Compatibility types, type aliases, and distinct types

2008-08-19 Thread Tom Lane
Peter Eisentraut <[EMAIL PROTECTED]> writes:
> One direction of the cast could be AS ASSIGNMENT, btw., but that is another 
> decision that would have to be worked out.

Making the back-cast be AS ASSIGNMENT would reduce the risks of
ambiguities, for sure.

regards, tom lane

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Compatibility types, type aliases, and distinct types

2008-08-19 Thread Peter Eisentraut
Am Monday, 18. August 2008 schrieb Tom Lane:
> If the type has no functions of its own, then the only way to make it
> easily usable is to throw in implicit conversions *in both directions*
> between it and the type it's an alias for.  You're going to find that
> that's a problem.

I'm not finding that that's a problem.  We have several cases of that in the 
standard catalogs already.  What kind of problem are you foreseeing?

One direction of the cast could be AS ASSIGNMENT, btw., but that is another 
decision that would have to be worked out.

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Compatibility types, type aliases, and distinct types

2008-08-18 Thread Tom Lane
Peter Eisentraut <[EMAIL PROTECTED]> writes:
> On Monday 18 August 2008 17:26:16 Tom Lane wrote:
> This feature by itself could be quite useful, and then we could simply
> add something like
> CREATE TYPE newtype AS oldtype WITH CASTS;
>> 
>> This seems like a great way to get lost in "ambiguous function" hell ...

> I don't understand this point.  No new overloaded functions are being defined.

If the type has no functions of its own, then the only way to make it
easily usable is to throw in implicit conversions *in both directions*
between it and the type it's an alias for.  You're going to find that
that's a problem.

regards, tom lane

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Compatibility types, type aliases, and distinct types

2008-08-18 Thread Peter Eisentraut
On Monday 18 August 2008 17:26:16 Tom Lane wrote:
> > This feature by itself could be quite useful, and then we could simply
> > add something like
> > CREATE TYPE newtype AS oldtype WITH CASTS;
>
> This seems like a great way to get lost in "ambiguous function" hell ...

I don't understand this point.  No new overloaded functions are being defined.

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Compatibility types, type aliases, and distinct types

2008-08-18 Thread Tom Lane
Peter Eisentraut <[EMAIL PROTECTED]> writes:
> So while thinking about how to make this simpler I remembered the "distinct 
> type" feature of SQL, which works quite similarly, namely the new type has 
> the same structure as the old type, but is a separate entity.  It looks like
> CREATE TYPE newtype AS oldtype;
> This feature by itself could be quite useful, and then we could simply add 
> something like
> CREATE TYPE newtype AS oldtype WITH CASTS;

This seems like a great way to get lost in "ambiguous function" hell ...

regards, tom lane

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Compatibility types, type aliases, and distinct types

2008-08-18 Thread Asko Oja
In my experience synonyms as well as rules are hacks and should be avoided
althou there are cases where they can save some work for dba's during
transitions from one situation to better one.

> There is also another possible way one might want to create a
compatibility
> type.  Instead of creating a new type, create an alias for an existing
type,
> much like we currently have built-in mappings for int -> int4, bigint ->
> int8, etc.  The difference here is that the type you put in is not the
same
> as the one you get dumped out.  So depending on taste and requirements, a
> user might want to choose the distinct type or the alias route.

Example or two would be helpful here where you expect this kind of
functionality be useful. Could you use it for defining Oracle compatibel
varchar2 and how would it work then?

On Mon, Aug 18, 2008 at 3:33 PM, Stephen Frost <[EMAIL PROTECTED]> wrote:

> * Peter Eisentraut ([EMAIL PROTECTED]) wrote:
> > There is also another possible way one might want to create a
> compatibility
> > type.  Instead of creating a new type, create an alias for an existing
> type,
> > much like we currently have built-in mappings for int -> int4, bigint ->
> > int8, etc.  The difference here is that the type you put in is not the
> same
> > as the one you get dumped out.  So depending on taste and requirements, a
> > user might want to choose the distinct type or the alias route.
>
> The alias route gets me thinking about Oracle synonyms..  That'd be nice
> to have in PG for a number of object types.  Most recently I was wishing
> I could create a schema synonym, though being able to do tables/views
> would have worked as well in that case, just a bit more work.
>
> > What do you think about adding this kind of support to PostgreSQL?
>  Obviously,
> > some details need to be worked out, but most of this is actually
> > straightforward catalog manipulation.
>
> I like the concept.  Not sure how much I'd end up using it, personally.
>
>Thanks,
>
>Stephen
>
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iEYEARECAAYFAkipbCgACgkQrzgMPqB3kiinmwCfROrhdu8YDpzsJvOtvpSW147O
> SOQAn3y/4MGadFz9VqDsmcm8fiKuxsn5
> =gdfU
> -END PGP SIGNATURE-
>
>


Re: [HACKERS] Compatibility types, type aliases, and distinct types

2008-08-18 Thread Stephen Frost
* Peter Eisentraut ([EMAIL PROTECTED]) wrote:
> There is also another possible way one might want to create a compatibility 
> type.  Instead of creating a new type, create an alias for an existing type, 
> much like we currently have built-in mappings for int -> int4, bigint -> 
> int8, etc.  The difference here is that the type you put in is not the same 
> as the one you get dumped out.  So depending on taste and requirements, a 
> user might want to choose the distinct type or the alias route.

The alias route gets me thinking about Oracle synonyms..  That'd be nice
to have in PG for a number of object types.  Most recently I was wishing
I could create a schema synonym, though being able to do tables/views
would have worked as well in that case, just a bit more work.

> What do you think about adding this kind of support to PostgreSQL?  
> Obviously, 
> some details need to be worked out, but most of this is actually 
> straightforward catalog manipulation.

I like the concept.  Not sure how much I'd end up using it, personally.

Thanks,

Stephen


signature.asc
Description: Digital signature


[HACKERS] Compatibility types, type aliases, and distinct types

2008-08-18 Thread Peter Eisentraut
I have been hacking around for a while trying to create some example Oracle 
compatibility types.  Canonical examples: varchar2 and number.  With the new 
features in 8.3 and 8.4, such as user-definable typmods and type categories, 
it appears to be actually possible to create a type equivalent to numeric or 
varchar entirely in user space.  Cool.

Actually doing this, however, appears to be shockingly complicated.  You need 
to redefine all the input/output/send/receive functions and all the cast 
functions and casts and then tie them all together.  I don't expect that this 
is something a user would succeed in, and not even an experienced developer 
would want to type all that in.  I actually had to write a script to generate 
all that code.

So while thinking about how to make this simpler I remembered the "distinct 
type" feature of SQL, which works quite similarly, namely the new type has 
the same structure as the old type, but is a separate entity.  It looks like

CREATE TYPE newtype AS oldtype;

This feature by itself could be quite useful, and then we could simply add 
something like

CREATE TYPE newtype AS oldtype WITH CASTS;

to copy all the casts as well, so the new type can be used in contexts where 
the old type could be used.

There is also another possible way one might want to create a compatibility 
type.  Instead of creating a new type, create an alias for an existing type, 
much like we currently have built-in mappings for int -> int4, bigint -> 
int8, etc.  The difference here is that the type you put in is not the same 
as the one you get dumped out.  So depending on taste and requirements, a 
user might want to choose the distinct type or the alias route.

What do you think about adding this kind of support to PostgreSQL?  Obviously, 
some details need to be worked out, but most of this is actually 
straightforward catalog manipulation.

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers