From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | James Harper <james(dot)harper(at)bendigoit(dot)com(dot)au> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: typmod for custom type |
Date: | 2014-02-16 16:28:57 |
Message-ID: | 18853.1392568137@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
James Harper <james(dot)harper(at)bendigoit(dot)com(dot)au> writes:
> I have created a custom type called my_numeric, which is roughly the same as the existing numeric type. I have declared in, 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_out function 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
From | Date | Subject | |
---|---|---|---|
Next Message | Ondřej Bouda | 2014-02-16 18:17:09 | Using pg_trigger.tgqual |
Previous Message | Adrian Klaver | 2014-02-16 15:15:01 | Re: typmod for custom type |