Re: typmod for custom type

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: typmod for custom type
Дата
Msg-id 18853.1392568137@sss.pgh.pa.us
обсуждение исходный текст
Ответ на typmod for custom type  (James Harper <james.harper@bendigoit.com.au>)
Список pgsql-general
James Harper <james.harper@bendigoit.com.au> writes:
> I have created a custom type called my_numeric, which is roughly the same as the existing numeric type. I have
declaredin, out, typmod_in, and typmod_out functions. I create a table like: 
> CREATE TABLE test (col1 my_numeric(6, 3));

> And then do \d test and can see that col1 is declared as (6, 3), which I think confirms that my typmod_in and
typmod_outfunction are correct. 

> But when I do:

> INSERT INTO test VALUES ('12.34');

> It behaves as though the typmod parameter to my in function
> (PG_GETARG_INT32(2)) is passed in as -1.

It might be.  In at least some cases the parser will generate a value as
unconstrained my_numeric and then expect to be able to cast that to the
constrained subtype.  Whether that's the case here or not, in general you
will need a length-coercion cast function to support a type like this.
IIRC, you can read about that in the CREATE CAST documentation.

            regards, tom lane


В списке pgsql-general по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: typmod for custom type
Следующее
От: Ondřej Bouda
Дата:
Сообщение: Using pg_trigger.tgqual