typemode for variable types

Started by Mohsen SMalmost 12 years ago5 messages
#1Mohsen SM
mohsensoodkhah@gmail.com

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.

#2Bruce Momjian
bruce@momjian.us
In reply to: Mohsen SM (#1)
Re: typemode for variable types

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@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ Everyone has their own god. +

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Bruce Momjian (#2)
Re: typemode for variable types

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

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#3)
Re: typemode for variable types

Alvaro Herrera <alvherre@2ndquadrant.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@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Greg Stark
stark@mit.edu
In reply to: Tom Lane (#4)
Re: typemode for variable types

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@sss.pgh.pa.us> wrote:

Show quoted text

Alvaro Herrera <alvherre@2ndquadrant.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@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers