1- /* $PostgreSQL: pgsql/contrib/citext/citext.sql.in,v 1.2 2008/07/30 17:08:52 tgl Exp $ */
1+ /* $PostgreSQL: pgsql/contrib/citext/citext.sql.in,v 1.3 2008/09/05 18:25:16 tgl Exp $ */
22
33-- Adjust this setting to control where the objects get created.
44SET search_path = public;
@@ -22,22 +22,22 @@ CREATE TYPE citext;
2222CREATE OR REPLACE FUNCTION citextin(cstring)
2323RETURNS citext
2424AS 'textin'
25- LANGUAGE' internal' IMMUTABLE STRICT;
25+ LANGUAGE internal IMMUTABLE STRICT;
2626
2727CREATE OR REPLACE FUNCTION citextout(citext)
2828RETURNS cstring
2929AS 'textout'
30- LANGUAGE' internal' IMMUTABLE STRICT;
30+ LANGUAGE internal IMMUTABLE STRICT;
3131
3232CREATE OR REPLACE FUNCTION citextrecv(internal)
3333RETURNS citext
3434AS 'textrecv'
35- LANGUAGE' internal' STABLE STRICT;
35+ LANGUAGE internal STABLE STRICT;
3636
3737CREATE OR REPLACE FUNCTION citextsend(citext)
3838RETURNS bytea
3939AS 'textsend'
40- LANGUAGE' internal' STABLE STRICT;
40+ LANGUAGE internal STABLE STRICT;
4141
4242--
4343-- The type itself.
@@ -56,13 +56,24 @@ CREATE TYPE citext (
5656);
5757
5858--
59- --A single cast function, since bpchar needs to have its whitespace trimmed
60- --before it's cast to citext .
59+ --Type casting functions for those situations where the I/O casts don't
60+ --automatically kick in .
6161--
62+
6263CREATE OR REPLACE FUNCTION citext(bpchar)
6364RETURNS citext
6465AS 'rtrim1'
65- LANGUAGE 'internal' IMMUTABLE STRICT;
66+ LANGUAGE internal IMMUTABLE STRICT;
67+
68+ CREATE OR REPLACE FUNCTION citext(boolean)
69+ RETURNS citext
70+ AS 'booltext'
71+ LANGUAGE internal IMMUTABLE STRICT;
72+
73+ CREATE OR REPLACE FUNCTION citext(inet)
74+ RETURNS citext
75+ AS 'network_show'
76+ LANGUAGE internal IMMUTABLE STRICT;
6677
6778--
6879-- Implicit and assignment type casts.
@@ -73,7 +84,9 @@ CREATE CAST (citext AS varchar) WITHOUT FUNCTION AS IMPLICIT;
7384CREATE CAST (citext AS bpchar) WITHOUT FUNCTION AS ASSIGNMENT;
7485CREATE CAST (text AS citext) WITHOUT FUNCTION AS ASSIGNMENT;
7586CREATE CAST (varchar AS citext) WITHOUT FUNCTION AS ASSIGNMENT;
76- CREATE CAST (bpchar AS citext) WITH FUNCTION citext(bpchar) AS ASSIGNMENT;
87+ CREATE CAST (bpchar AS citext) WITH FUNCTION citext(bpchar) AS ASSIGNMENT;
88+ CREATE CAST (boolean AS citext) WITH FUNCTION citext(boolean) AS ASSIGNMENT;
89+ CREATE CAST (inet AS citext) WITH FUNCTION citext(inet) AS ASSIGNMENT;
7790
7891--
7992-- Operator Functions.
@@ -243,19 +256,19 @@ CREATE AGGREGATE max(citext) (
243256
244257CREATE OR REPLACE FUNCTION texticlike(citext, citext)
245258RETURNS bool AS 'texticlike'
246- LANGUAGE' internal' IMMUTABLE STRICT;
259+ LANGUAGE internal IMMUTABLE STRICT;
247260
248261CREATE OR REPLACE FUNCTION texticnlike(citext, citext)
249262RETURNS bool AS 'texticnlike'
250- LANGUAGE' internal' IMMUTABLE STRICT;
263+ LANGUAGE internal IMMUTABLE STRICT;
251264
252265CREATE OR REPLACE FUNCTION texticregexeq(citext, citext)
253266RETURNS bool AS 'texticregexeq'
254- LANGUAGE' internal' IMMUTABLE STRICT;
267+ LANGUAGE internal IMMUTABLE STRICT;
255268
256269CREATE OR REPLACE FUNCTION texticregexne(citext, citext)
257270RETURNS bool AS 'texticregexne'
258- LANGUAGE' internal' IMMUTABLE STRICT;
271+ LANGUAGE internal IMMUTABLE STRICT;
259272
260273CREATE OPERATOR ~ (
261274 PROCEDURE = texticregexeq,
@@ -335,19 +348,19 @@ CREATE OPERATOR !~~* (
335348
336349CREATE OR REPLACE FUNCTION texticlike(citext, text)
337350RETURNS bool AS 'texticlike'
338- LANGUAGE' internal' IMMUTABLE STRICT;
351+ LANGUAGE internal IMMUTABLE STRICT;
339352
340353CREATE OR REPLACE FUNCTION texticnlike(citext, text)
341354RETURNS bool AS 'texticnlike'
342- LANGUAGE' internal' IMMUTABLE STRICT;
355+ LANGUAGE internal IMMUTABLE STRICT;
343356
344357CREATE OR REPLACE FUNCTION texticregexeq(citext, text)
345358RETURNS bool AS 'texticregexeq'
346- LANGUAGE' internal' IMMUTABLE STRICT;
359+ LANGUAGE internal IMMUTABLE STRICT;
347360
348361CREATE OR REPLACE FUNCTION texticregexne(citext, text)
349362RETURNS bool AS 'texticregexne'
350- LANGUAGE' internal' IMMUTABLE STRICT;
363+ LANGUAGE internal IMMUTABLE STRICT;
351364
352365CREATE OPERATOR ~ (
353366 PROCEDURE = texticregexeq,
@@ -420,3 +433,56 @@ CREATE OPERATOR !~~* (
420433 RESTRICT = icnlikesel,
421434 JOIN = icnlikejoinsel
422435);
436+
437+ --
438+ -- Matching citext in string comparison functions.
439+ -- XXX TODO Ideally these would be implemented in C.
440+ --
441+
442+ CREATE OR REPLACE FUNCTION regexp_matches( citext, citext ) RETURNS TEXT[] AS $$
443+ SELECT pg_catalog.regexp_matches( $1::pg_catalog.text, $2::pg_catalog.text, 'i' );
444+ $$ LANGUAGE SQL IMMUTABLE STRICT;
445+
446+ CREATE OR REPLACE FUNCTION regexp_matches( citext, citext, text ) RETURNS TEXT[] AS $$
447+ SELECT pg_catalog.regexp_matches( $1::pg_catalog.text, $2::pg_catalog.text, CASE WHEN pg_catalog.strpos($3, 'c') = 0 THEN $3 || 'i' ELSE $3 END );
448+ $$ LANGUAGE SQL IMMUTABLE STRICT;
449+
450+ CREATE OR REPLACE FUNCTION regexp_replace( citext, citext, text ) returns TEXT AS $$
451+ SELECT pg_catalog.regexp_replace( $1::pg_catalog.text, $2::pg_catalog.text, $3, 'i');
452+ $$ LANGUAGE SQL IMMUTABLE STRICT;
453+
454+ CREATE OR REPLACE FUNCTION regexp_replace( citext, citext, text, text ) returns TEXT AS $$
455+ SELECT pg_catalog.regexp_replace( $1::pg_catalog.text, $2::pg_catalog.text, $3, CASE WHEN pg_catalog.strpos($4, 'c') = 0 THEN $4 || 'i' ELSE $4 END);
456+ $$ LANGUAGE SQL IMMUTABLE STRICT;
457+
458+ CREATE OR REPLACE FUNCTION regexp_split_to_array( citext, citext ) RETURNS TEXT[] AS $$
459+ SELECT pg_catalog.regexp_split_to_array( $1::pg_catalog.text, $2::pg_catalog.text, 'i' );
460+ $$ LANGUAGE SQL IMMUTABLE STRICT;
461+
462+ CREATE OR REPLACE FUNCTION regexp_split_to_array( citext, citext, text ) RETURNS TEXT[] AS $$
463+ SELECT pg_catalog.regexp_split_to_array( $1::pg_catalog.text, $2::pg_catalog.text, CASE WHEN pg_catalog.strpos($3, 'c') = 0 THEN $3 || 'i' ELSE $3 END );
464+ $$ LANGUAGE SQL IMMUTABLE STRICT;
465+
466+ CREATE OR REPLACE FUNCTION regexp_split_to_table( citext, citext ) RETURNS SETOF TEXT AS $$
467+ SELECT pg_catalog.regexp_split_to_table( $1::pg_catalog.text, $2::pg_catalog.text, 'i' );
468+ $$ LANGUAGE SQL IMMUTABLE STRICT;
469+
470+ CREATE OR REPLACE FUNCTION regexp_split_to_table( citext, citext, text ) RETURNS SETOF TEXT AS $$
471+ SELECT pg_catalog.regexp_split_to_table( $1::pg_catalog.text, $2::pg_catalog.text, CASE WHEN pg_catalog.strpos($3, 'c') = 0 THEN $3 || 'i' ELSE $3 END );
472+ $$ LANGUAGE SQL IMMUTABLE STRICT;
473+
474+ CREATE OR REPLACE FUNCTION strpos( citext, citext ) RETURNS INT AS $$
475+ SELECT pg_catalog.strpos( pg_catalog.lower( $1::pg_catalog.text ), pg_catalog.lower( $2::pg_catalog.text ) );
476+ $$ LANGUAGE SQL IMMUTABLE STRICT;
477+
478+ CREATE OR REPLACE FUNCTION replace( citext, citext, citext ) RETURNS TEXT AS $$
479+ SELECT pg_catalog.regexp_replace( $1::pg_catalog.text, pg_catalog.regexp_replace($2::pg_catalog.text, '([^a-zA-Z_0-9])', E'\\\\\\1', 'g'), $3::pg_catalog.text, 'gi' );
480+ $$ LANGUAGE SQL IMMUTABLE STRICT;
481+
482+ CREATE OR REPLACE FUNCTION split_part( citext, citext, int ) RETURNS TEXT AS $$
483+ SELECT (pg_catalog.regexp_split_to_array( $1::pg_catalog.text, pg_catalog.regexp_replace($2::pg_catalog.text, '([^a-zA-Z_0-9])', E'\\\\\\1', 'g'), 'i'))[$3];
484+ $$ LANGUAGE SQL IMMUTABLE STRICT;
485+
486+ CREATE OR REPLACE FUNCTION translate( citext, citext, text ) RETURNS TEXT AS $$
487+ SELECT pg_catalog.translate( pg_catalog.translate( $1::pg_catalog.text, pg_catalog.lower($2::pg_catalog.text), $3), pg_catalog.upper($2::pg_catalog.text), $3);
488+ $$ LANGUAGE SQL IMMUTABLE STRICT;