Re: typemode for variable types

Lists: pgsql-hackers
From: Mohsen SM <mohsensoodkhah(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: typemode for variable types
Date: 2014-02-23 04:20:08
Message-ID: CAGT6x6ebREYR5YKw=QsNx+GB1aiZ4OuQGqAWi6PYrXzVvUdOvQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello.
I have a new type similar to varchar.
I want to fine how did I can to calculate typemod
and where must I calculate typemod for this type.
thanks.


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Mohsen SM <mohsensoodkhah(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: typemode for variable types
Date: 2014-02-24 20:16:51
Message-ID: 20140224201651.GK16943@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Feb 23, 2014 at 07:50:08AM +0330, Mohsen SM wrote:
> Hello.
> I have a new type similar to varchar.
> I want to fine how did I can to calculate typemod
> and where must I calculate typemod for this type.

Well, typmods are type-specific, so there is no official way to
calculate it. I would look at how an existing type uses typmod and copy
that.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ Everyone has their own god. +


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Mohsen SM <mohsensoodkhah(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: typemode for variable types
Date: 2014-02-24 20:24:10
Message-ID: 20140224202410.GT4759@eldon.alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian escribió:
> On Sun, Feb 23, 2014 at 07:50:08AM +0330, Mohsen SM wrote:
> > Hello.
> > I have a new type similar to varchar.
> > I want to fine how did I can to calculate typemod
> > and where must I calculate typemod for this type.
>
> Well, typmods are type-specific, so there is no official way to
> calculate it. I would look at how an existing type uses typmod and copy
> that.

Our system is pretty neat. See a complex example here:
https://github.com/postgis/postgis/blob/svn-trunk/postgis/gserialized_typmod.c

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Mohsen SM <mohsensoodkhah(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: typemode for variable types
Date: 2014-02-24 20:34:13
Message-ID: 9068.1393274053@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> writes:
> Bruce Momjian escribi:
>> Well, typmods are type-specific, so there is no official way to
>> calculate it. I would look at how an existing type uses typmod and copy
>> that.

> Our system is pretty neat. See a complex example here:
> https://github.com/postgis/postgis/blob/svn-trunk/postgis/gserialized_typmod.c

One other point is that if you do consult the varchar functions as
an example, be aware that there's an offset of 4 in their definition
of the typmod (eg, for varchar(3) the stored typmod is 7). This is
entirely for legacy reasons so there's no good reason to duplicate it
in a new custom-made type. Except for the rule that negative values
mean "unspecified typmod" (which you have to support), you can
define the contents of the typmod value however you want.

regards, tom lane


From: Greg Stark <stark(at)mit(dot)edu>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, pgsql-hackers(at)postgresql(dot)org, Mohsen SM <mohsensoodkhah(at)gmail(dot)com>
Subject: Re: typemode for variable types
Date: 2014-02-25 12:59:50
Message-ID: CAM-w4HMcShT0-mr06vzqTLNUJ76=h0mpdJBaCSEJ7sPfb0hAHg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Also keep in mind that the system doesn't always retain the typmod. So the
datum should be possible to interpret without the typmod. Incidental
effects such as length limits or precision displayed are ok but the meaning
shouldn't be changed.

--
greg
On 24 Feb 2014 20:34, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> writes:
> > Bruce Momjian escribió:
> >> Well, typmods are type-specific, so there is no official way to
> >> calculate it. I would look at how an existing type uses typmod and copy
> >> that.
>
> > Our system is pretty neat. See a complex example here:
> >
> https://github.com/postgis/postgis/blob/svn-trunk/postgis/gserialized_typmod.c
>
> One other point is that if you do consult the varchar functions as
> an example, be aware that there's an offset of 4 in their definition
> of the typmod (eg, for varchar(3) the stored typmod is 7). This is
> entirely for legacy reasons so there's no good reason to duplicate it
> in a new custom-made type. Except for the rule that negative values
> mean "unspecified typmod" (which you have to support), you can
> define the contents of the typmod value however you want.
>
> regards, tom lane
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>