typmod is always -1 - Mailing list pgsql-hackers

From Pavel Stehule
Subject typmod is always -1
Date
Msg-id 162867790903161317q178e11e6ie276d1254c279dd1@mail.gmail.com
Whole thread Raw
Responses Re: typmod is always -1  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hello

I am playing with custom typmod. I did simple wrapper over varchar type.

PG_FUNCTION_INFO_V1(mvarcharin);

Datum
mvarcharin(PG_FUNCTION_ARGS)
{
elog(NOTICE, ">>>>>>>>%d", PG_GETARG_INT32(2));       return DirectFunctionCall3(varchar,
           DirectFunctionCall3(varcharin, 
    PG_GETARG_DATUM(0),
    PG_GETARG_DATUM(1),
    Int32GetDatum(-1)),                                           PG_GETARG_DATUM(2),/* original typmod */
                            BoolGetDatum(true));/* explit casting, quite truncate */ 
}


CREATE TYPE mvarchar (       INPUT = mvarcharin,       OUTPUT = mvarcharout,       LIKE = pg_catalog.varchar,
typmod_in= pg_catalog.varchartypmodin,       typmod_out = pg_catalog.varchartypmodout 
);

I have a problem - every call of mvarcharin is with typmod = -1.

postgres=# create table x(a mvarchar(3));
CREATE TABLE
Time: 29,930 ms
postgres=# \d x         Table "public.x"
┌────────┬─────────────┬───────────┐
│ Column │ Type        │ Modifiers │
├────────┴─────────────┴───────────┤
│ a      │ mvarchar(3) │           │
└──────────────────────────────────┘


postgres=# INSERT INTO x values('abcdef');
NOTICE:  >>>>>>>>-1
INSERT 0 1
Time: 2,244 ms
postgres=#

can somebody navigate me?

regards
Pavel Stehule

pgsql-hackers by date:

Previous
From: "Jonah H. Harris"
Date:
Subject: Re: Problem with accesing Oracle from plperlu functionwhen using remote pg client.
Next
From: Tom Lane
Date:
Subject: Re: small but useful patches for text search