Re: PATCH: CITEXT 2.0 v4
David Wheeler <david@kineticode.com>
From: "David E. Wheeler" <david@kineticode.com>
To: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Cc: Michael Paesold <mpaesold@gmx.at>, Robert Treat <xzilla@users.sourceforge.net>
Date: 2008-07-21T18:55:51Z
Lists: pgsql-hackers
On Jul 18, 2008, at 09:53, David E. Wheeler wrote:
> However, if someone with a lot more C and Pg core knowledge wanted
> to sit down with me for a couple hours next week and help me bang
> out these functions, that would be great. I'd love to have the
> implementation be that much more complete.
I've implemented fixes for the regexp_* functions and strpos() in pure
SQL, like so:
CREATE OR REPLACE FUNCTION regexp_matches( citext, citext ) RETURNS
TEXT[] AS '
SELECT regexp_matches( $1::text, $2::text, ''i'' );
' LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION regexp_matches( citext, citext, text )
RETURNS TEXT[] AS '
SELECT regexp_matches( $1::text, $2::text, CASE WHEN strpos($3,
''c'') = 0 THEN $3 || ''i'' ELSE $3 END );
' LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION regexp_replace( citext, citext, text )
returns TEXT AS '
SELECT regexp_replace( $1::text, $2::text, $3, ''i'');
' LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION regexp_replace( citext, citext, text,
text ) returns TEXT AS '
SELECT regexp_replace( $1::text, $2::text, $3, CASE WHEN
strpos($4, ''c'') = 0 THEN $4 || ''i'' ELSE $4 END);
' LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION regexp_split_to_array( citext, citext )
RETURNS TEXT[] AS '
SELECT regexp_split_to_array( $1::text, $2::text, ''i'' );
' LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION regexp_split_to_array( citext, citext,
text ) RETURNS TEXT[] AS '
SELECT regexp_split_to_array( $1::text, $2::text, CASE WHEN
strpos($3, ''c'') = 0 THEN $3 || ''i'' ELSE $3 END );
' LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION regexp_split_to_table( citext, citext )
RETURNS SETOF TEXT AS '
SELECT regexp_split_to_table( $1::text, $2::text, ''i'' );
' LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION regexp_split_to_table( citext, citext,
text ) RETURNS SETOF TEXT AS '
SELECT regexp_split_to_table( $1::text, $2::text, CASE WHEN
strpos($3, ''c'') = 0 THEN $3 || ''i'' ELSE $3 END );
' LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION strpos( citext, citext ) RETURNS INT AS '
SELECT strpos( LOWER( $1::text ), LOWER( $2::text ) );
' LANGUAGE SQL IMMUTABLE STRICT;
Not so bad, though it'd be nice to have C functions that just did
these things. Still not case-insensitive are:
-- replace()
-- split_part()
-- translate()
So, anyone at OSCON this week want to help me with these? Or to
convert the above functions to C? Greg? Bruce?
Thanks,
David