Re: [GENERAL] Trying to add a type modifier to user created type
Carsten Kropf wrote: Hi *, I have the following problem: I wanted to add a new type that supports modifiers (comparable to numeric/varchar). I succeeded in adding the type modifier functions to my new type. These methods are called and the modifier is set. However the modifiers are not applied here. I don't know exactly how to get the modifiers to be applied to my type. I looked into the source code of varchar/numeric and a function called the same name as the type is added in there that gets called with a value of the particular type and the typmod, respectively. But I don't know, how to register this function properly in order to get called, when sth is to be stored in the database. column. How can I achieve this/What do I have to do to get it to work? It's been a while but I still remember exactly the same question (frustration?) from some while ago (maybe it is something for the docs) You need to add a cast from the type to itself, e.g. -- typmod coercion CREATE CAST (complex AS complex) WITH FUNCTION complextypmod(complex,int4) AS IMPLICIT; Where complextypemod would be the typmod apply functions (int4 is the typmod) Regards, Yeb Havinga -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] Trying to add a type modifier to user created type
Yeb Havinga yebhavi...@gmail.com writes: Carsten Kropf wrote: I wanted to add a new type that supports modifiers (comparable to numeric/varchar). You need to add a cast from the type to itself, e.g. The CREATE CAST reference page has the gory details here. regards, tom lane -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] Trying to add a type modifier to user created type
Thanks a lot so far, got it working with the cast. Probably the documentation about create type where the type modifiers are described should be extended in order to find that. Thanks and regards Carsten Kropf Am 18.02.2010 um 16:46 schrieb Tom Lane: Yeb Havinga yebhavi...@gmail.com writes: Carsten Kropf wrote: I wanted to add a new type that supports modifiers (comparable to numeric/varchar). You need to add a cast from the type to itself, e.g. The CREATE CAST reference page has the gory details here. regards, tom lane -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
[GENERAL] Trying to add a type modifier to user created type
Hi *, I have the following problem: I wanted to add a new type that supports modifiers (comparable to numeric/varchar). I succeeded in adding the type modifier functions to my new type. These methods are called and the modifier is set. However the modifiers are not applied here. I don't know exactly how to get the modifiers to be applied to my type. I looked into the source code of varchar/numeric and a function called the same name as the type is added in there that gets called with a value of the particular type and the typmod, respectively. But I don't know, how to register this function properly in order to get called, when sth is to be stored in the database. I also set up such a function and registered it in pg_proc (just called create function and made it public like this). My problem is that I don't know how to tell the database system when to call my function. I don't see any possibility to do this here. Even reading the code of numeric/varchar didn't help, because it just works in there. Where do I have to set up that this function is to be called when the modifier is to be applied? I thought, there would be something magic that just calls the function named as the given type in order to apply the modifiers. My modifier function, however is never called. The type modifiers (typmodin and typmodout) are called properly when requesting a description of the particular table or setting the modifier. However, unfortunately, it is never applied to my column. How can I achieve this/What do I have to do to get it to work? Best regards Carsten Kropf -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general