Create Type with typmod_in

Поиск
Список
Период
Сортировка
Искать

Create Type with typmod_in

От:
Russell Keane <Russell.Keane@inps.co.uk>
Дата:

I’m trying to create a custom type (PostgreSQL 9.0) which will essentially auto truncate a string to a certain length.

 

The type (auto_trunc_char) will be used as follows:

 

Create table blah (

                Some_name auto_trunc_char(40)

)

 

Can this be done purely in plpgsql?

If so, how?

 

I know I have to declare the following (at least) but I’m not sure how to flesh out the functions:

 

create type auto_trunc_char (

                INTERNALLENGTH = VARIABLE,

                INPUT = auto_trunc_char_in_function,

                OUTPUT = auto_trunc_char_out_function,

                TYPMOD_IN = auto_trunc_char_modifier_in

);

 

 

Regards,

 

Russell Keane

INPS

 

Subscribe to the Vision e-newsletter

Subscribe to the Helpline Support Bulletin

  Subscribe to the Helpline Blog RSS Feed

 



Registered name: In Practice Systems Ltd.
Registered address: The Bread Factory, 1a Broughton Street, London, SW8 3QJ
Registered Number: 1788577
Registered in England
Visit our Internet Web site at www.inps.co.uk
The information in this internet email is confidential and is intended solely for the addressee. Access, copying or re-use of information in it by anyone else is not authorised. Any views or opinions presented are solely those of the author and do not necessarily represent those of INPS or any of its affiliates. If you are not the intended recipient please contact is.helpdesk@inps.co.uk

Re: Create Type with typmod_in

От:
David Johnston <polobo@yahoo.com>
Дата:
On Nov 4, 2011, at 10:01, Russell Keane <Russell.Keane@inps.co.uk> wrote:

I’m trying to create a custom type (PostgreSQL 9.0) which will essentially auto truncate a string to a certain length.

 


Can this be done purely in plpgsql?

If so, how?

 


An explicit cast of a value to varchar(n) causes the value to be truncated to n characters.

E.g.,  '1234567'::varchar(5) -> '12345'

How to integrate that knowledge into a type I do not know.

David J.


FAQ