Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5bc561a

Browse files
committed
Add some additional casts and regression tests for the citext data type.
David Wheeler
1 parentf536f74 commit5bc561a

File tree

5 files changed

+3981
-91
lines changed

5 files changed

+3981
-91
lines changed

‎contrib/citext/citext.sql.in

Lines changed: 83 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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.
44
SET search_path = public;
@@ -22,22 +22,22 @@ CREATE TYPE citext;
2222
CREATE OR REPLACE FUNCTION citextin(cstring)
2323
RETURNS citext
2424
AS 'textin'
25-
LANGUAGE'internal' IMMUTABLE STRICT;
25+
LANGUAGE internal IMMUTABLE STRICT;
2626

2727
CREATE OR REPLACE FUNCTION citextout(citext)
2828
RETURNS cstring
2929
AS 'textout'
30-
LANGUAGE'internal' IMMUTABLE STRICT;
30+
LANGUAGE internal IMMUTABLE STRICT;
3131

3232
CREATE OR REPLACE FUNCTION citextrecv(internal)
3333
RETURNS citext
3434
AS 'textrecv'
35-
LANGUAGE'internal' STABLE STRICT;
35+
LANGUAGE internal STABLE STRICT;
3636

3737
CREATE OR REPLACE FUNCTION citextsend(citext)
3838
RETURNS bytea
3939
AS '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+
6263
CREATE OR REPLACE FUNCTION citext(bpchar)
6364
RETURNS citext
6465
AS '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;
7384
CREATE CAST (citext AS bpchar) WITHOUT FUNCTION AS ASSIGNMENT;
7485
CREATE CAST (text AS citext) WITHOUT FUNCTION AS ASSIGNMENT;
7586
CREATE 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

244257
CREATE OR REPLACE FUNCTION texticlike(citext, citext)
245258
RETURNS bool AS 'texticlike'
246-
LANGUAGE'internal' IMMUTABLE STRICT;
259+
LANGUAGE internal IMMUTABLE STRICT;
247260

248261
CREATE OR REPLACE FUNCTION texticnlike(citext, citext)
249262
RETURNS bool AS 'texticnlike'
250-
LANGUAGE'internal' IMMUTABLE STRICT;
263+
LANGUAGE internal IMMUTABLE STRICT;
251264

252265
CREATE OR REPLACE FUNCTION texticregexeq(citext, citext)
253266
RETURNS bool AS 'texticregexeq'
254-
LANGUAGE'internal' IMMUTABLE STRICT;
267+
LANGUAGE internal IMMUTABLE STRICT;
255268

256269
CREATE OR REPLACE FUNCTION texticregexne(citext, citext)
257270
RETURNS bool AS 'texticregexne'
258-
LANGUAGE'internal' IMMUTABLE STRICT;
271+
LANGUAGE internal IMMUTABLE STRICT;
259272

260273
CREATE OPERATOR ~ (
261274
PROCEDURE = texticregexeq,
@@ -335,19 +348,19 @@ CREATE OPERATOR !~~* (
335348

336349
CREATE OR REPLACE FUNCTION texticlike(citext, text)
337350
RETURNS bool AS 'texticlike'
338-
LANGUAGE'internal' IMMUTABLE STRICT;
351+
LANGUAGE internal IMMUTABLE STRICT;
339352

340353
CREATE OR REPLACE FUNCTION texticnlike(citext, text)
341354
RETURNS bool AS 'texticnlike'
342-
LANGUAGE'internal' IMMUTABLE STRICT;
355+
LANGUAGE internal IMMUTABLE STRICT;
343356

344357
CREATE OR REPLACE FUNCTION texticregexeq(citext, text)
345358
RETURNS bool AS 'texticregexeq'
346-
LANGUAGE'internal' IMMUTABLE STRICT;
359+
LANGUAGE internal IMMUTABLE STRICT;
347360

348361
CREATE OR REPLACE FUNCTION texticregexne(citext, text)
349362
RETURNS bool AS 'texticregexne'
350-
LANGUAGE'internal' IMMUTABLE STRICT;
363+
LANGUAGE internal IMMUTABLE STRICT;
351364

352365
CREATE 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;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp