custom type similar to varchar(#)

Started by Jeff Davisover 23 years ago2 messagesgeneral
Jump to latest
#1Jeff Davis
pgsql@j-davis.com

I think that this question was adressed before, but I looked around and
couldn't find the answer.

I would like to try to emulate the behavior of the old style varchar(#), in
which it automatically truncated values that were oversized. To do this, it
occured to me to try making a custom type, but for that I would need to
accept the numerical argument as part of the type. I could not find any way
in the documentation to create such a type. It would occur to me that I could
try to use the atttypmod value as varchar appearently does, but I'm not sure
exactly how to do that.

Any suggestions?

Thanks,
Jeff

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jeff Davis (#1)
Re: custom type similar to varchar(#)

Jeff Davis <list-pgsql-general@empires.org> writes:

I would like to try to emulate the behavior of the old style varchar(#), in
which it automatically truncated values that were oversized. To do this, it
occured to me to try making a custom type, but for that I would need to
accept the numerical argument as part of the type. I could not find any way
in the documentation to create such a type.

varchar and other types with special syntax require special processing
in the parser. If you're not afraid of yacc grammars then you could
hack up gram.y to add another special type name. On the whole, though,
you might prefer to go and revert the change in the varchar limit-check
routine ...

regards, tom lane