CREATE TYPE for case insensitive text and varchar

Started by Daniel Migowskiabout 22 years ago3 messages
#1Daniel Migowski
nur-gueltig-bis-2003-12-01@Mig-O.de

Hallo.

i just coded a new datatype named "cistring", that can be
used in every function that accepts text or varchar, and has
the great ability to be ordered case insensitive in ORDER BY-
Clauses and Indices. The problem is, that its coded like the
text-type, so it is variable length completly.

I miss the possibility to code something like a userdifined
varchar(n). I don't know how to create an input function,
that accepts the size of the type, or a function, how to declare
such types at all. I think, somethink like a userdefined
numeric(n,m) isn't possible, too, or am I wrong?

Thank you for all replies,
Daniel Migowski

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Daniel Migowski (#1)
Re: CREATE TYPE for case insensitive text and varchar

Daniel Migowski <nur-gueltig-bis-2003-12-01@Mig-O.de> writes:

I miss the possibility to code something like a userdifined
varchar(n).

You're out of luck on that. The data types that can have precision
parameters attached to them are hard-wired into the parser.

regards, tom lane

#3Jan Wieck
JanWieck@Yahoo.com
In reply to: Tom Lane (#2)
1 attachment(s)
Re: CREATE TYPE for case insensitive text and varchar

Tom Lane wrote:

Daniel Migowski <nur-gueltig-bis-2003-12-01@Mig-O.de> writes:

I miss the possibility to code something like a userdifined
varchar(n).

You're out of luck on that. The data types that can have precision
parameters attached to them are hard-wired into the parser.

Maybe you don't need to invent a whole new data type but the existing
varchar can serve just fine?

The attached script for version 7.3.4 (does not work with 7.4)
demonstrates how to add case insensitive operators *=, *> and so on
including an operator class for btree to the existing varchar.

All one has to do is to use *= instead of = in queries. Indexes, even
unique, based on case insensitive comparision are possible too and well
supported. The only thing I think wouldn't work are IN and NOT IN
constructs.

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck@Yahoo.com #

Attachments:

case_insensitive_varchar.shtext/plain; name=case_insensitive_varchar.shDownload