Skip to content

Commit f9d747a

Browse files
committed
Support the new regexp_match() function for citext.
Emre Hasegeli Patch: <CAE2gYzzF24ZHWqkMukkHwqa0otbES9Rex22LrjQUNbi=oKziNQ@mail.gmail.com>
1 parent 9f31e45 commit f9d747a

File tree

8 files changed

+149
-3
lines changed

8 files changed

+149
-3
lines changed

contrib/citext/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
MODULES = citext
44

55
EXTENSION = citext
6-
DATA = citext--1.3.sql citext--1.2--1.3.sql citext--1.1--1.2.sql \
6+
DATA = citext--1.4.sql citext--1.3--1.4.sql \
7+
citext--1.2--1.3.sql citext--1.1--1.2.sql \
78
citext--1.0--1.1.sql citext--unpackaged--1.0.sql
89
PGFILEDESC = "citext - case-insensitive character string data type"
910

contrib/citext/citext--1.3--1.4.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* contrib/citext/citext--1.3--1.4.sql */
2+
3+
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
4+
\echo Use "ALTER EXTENSION citext UPDATE TO '1.4'" to load this file. \quit
5+
6+
CREATE FUNCTION regexp_match( citext, citext ) RETURNS TEXT[] AS $$
7+
SELECT pg_catalog.regexp_match( $1::pg_catalog.text, $2::pg_catalog.text, 'i' );
8+
$$ LANGUAGE SQL IMMUTABLE STRICT PARALLEL SAFE;
9+
10+
CREATE FUNCTION regexp_match( citext, citext, text ) RETURNS TEXT[] AS $$
11+
SELECT pg_catalog.regexp_match( $1::pg_catalog.text, $2::pg_catalog.text, CASE WHEN pg_catalog.strpos($3, 'c') = 0 THEN $3 || 'i' ELSE $3 END );
12+
$$ LANGUAGE SQL IMMUTABLE STRICT PARALLEL SAFE;

contrib/citext/citext--1.3.sql renamed to contrib/citext/citext--1.4.sql

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* contrib/citext/citext--1.2.sql */
1+
/* contrib/citext/citext--1.4.sql */
22

33
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
44
\echo Use "CREATE EXTENSION citext" to load this file. \quit
@@ -444,6 +444,14 @@ CREATE OPERATOR !~~* (
444444
-- XXX TODO Ideally these would be implemented in C.
445445
--
446446

447+
CREATE FUNCTION regexp_match( citext, citext ) RETURNS TEXT[] AS $$
448+
SELECT pg_catalog.regexp_match( $1::pg_catalog.text, $2::pg_catalog.text, 'i' );
449+
$$ LANGUAGE SQL IMMUTABLE STRICT PARALLEL SAFE;
450+
451+
CREATE FUNCTION regexp_match( citext, citext, text ) RETURNS TEXT[] AS $$
452+
SELECT pg_catalog.regexp_match( $1::pg_catalog.text, $2::pg_catalog.text, CASE WHEN pg_catalog.strpos($3, 'c') = 0 THEN $3 || 'i' ELSE $3 END );
453+
$$ LANGUAGE SQL IMMUTABLE STRICT PARALLEL SAFE;
454+
447455
CREATE FUNCTION regexp_matches( citext, citext ) RETURNS SETOF TEXT[] AS $$
448456
SELECT pg_catalog.regexp_matches( $1::pg_catalog.text, $2::pg_catalog.text, 'i' );
449457
$$ LANGUAGE SQL IMMUTABLE STRICT PARALLEL SAFE ROWS 1;

contrib/citext/citext.control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# citext extension
22
comment = 'data type for case-insensitive character strings'
3-
default_version = '1.3'
3+
default_version = '1.4'
44
module_pathname = '$libdir/citext'
55
relocatable = true

contrib/citext/expected/citext.out

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,6 +1770,60 @@ SELECT quote_literal( name ) = quote_literal( name::text ) AS t FROM srt;
17701770
t
17711771
(4 rows)
17721772

1773+
SELECT regexp_match('foobarbequebaz'::citext, '(bar)(beque)') = ARRAY[ 'bar', 'beque' ] AS t;
1774+
t
1775+
---
1776+
t
1777+
(1 row)
1778+
1779+
SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)') = ARRAY[ 'bar', 'beque' ] AS t;
1780+
t
1781+
---
1782+
t
1783+
(1 row)
1784+
1785+
SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext) = ARRAY[ 'bar', 'beque' ] AS t;
1786+
t
1787+
---
1788+
t
1789+
(1 row)
1790+
1791+
SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, '') = ARRAY[ 'bar', 'beque' ] AS t;
1792+
t
1793+
---
1794+
t
1795+
(1 row)
1796+
1797+
SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)', '') = ARRAY[ 'bar', 'beque' ] AS t;
1798+
t
1799+
---
1800+
t
1801+
(1 row)
1802+
1803+
SELECT regexp_match('foobarbequebaz', '(BAR)(BEQUE)'::citext, '') = ARRAY[ 'bar', 'beque' ] AS t;
1804+
t
1805+
---
1806+
t
1807+
(1 row)
1808+
1809+
SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, ''::citext) = ARRAY[ 'bar', 'beque' ] AS t;
1810+
t
1811+
---
1812+
t
1813+
(1 row)
1814+
1815+
-- c forces case-sensitive
1816+
SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, 'c'::citext) = ARRAY[ 'bar', 'beque' ] AS "no result";
1817+
no result
1818+
-----------
1819+
1820+
(1 row)
1821+
1822+
-- g is not allowed
1823+
SELECT regexp_match('foobarbequebazmorebarbequetoo'::citext, '(BAR)(BEQUE)'::citext, 'g') AS "error";
1824+
ERROR: regexp_match does not support the global option
1825+
HINT: Use the regexp_matches function instead.
1826+
CONTEXT: SQL function "regexp_match" statement 1
17731827
SELECT regexp_matches('foobarbequebaz'::citext, '(bar)(beque)') = ARRAY[ 'bar', 'beque' ] AS t;
17741828
t
17751829
---

contrib/citext/expected/citext_1.out

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,6 +1770,60 @@ SELECT quote_literal( name ) = quote_literal( name::text ) AS t FROM srt;
17701770
t
17711771
(4 rows)
17721772

1773+
SELECT regexp_match('foobarbequebaz'::citext, '(bar)(beque)') = ARRAY[ 'bar', 'beque' ] AS t;
1774+
t
1775+
---
1776+
t
1777+
(1 row)
1778+
1779+
SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)') = ARRAY[ 'bar', 'beque' ] AS t;
1780+
t
1781+
---
1782+
t
1783+
(1 row)
1784+
1785+
SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext) = ARRAY[ 'bar', 'beque' ] AS t;
1786+
t
1787+
---
1788+
t
1789+
(1 row)
1790+
1791+
SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, '') = ARRAY[ 'bar', 'beque' ] AS t;
1792+
t
1793+
---
1794+
t
1795+
(1 row)
1796+
1797+
SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)', '') = ARRAY[ 'bar', 'beque' ] AS t;
1798+
t
1799+
---
1800+
t
1801+
(1 row)
1802+
1803+
SELECT regexp_match('foobarbequebaz', '(BAR)(BEQUE)'::citext, '') = ARRAY[ 'bar', 'beque' ] AS t;
1804+
t
1805+
---
1806+
t
1807+
(1 row)
1808+
1809+
SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, ''::citext) = ARRAY[ 'bar', 'beque' ] AS t;
1810+
t
1811+
---
1812+
t
1813+
(1 row)
1814+
1815+
-- c forces case-sensitive
1816+
SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, 'c'::citext) = ARRAY[ 'bar', 'beque' ] AS "no result";
1817+
no result
1818+
-----------
1819+
1820+
(1 row)
1821+
1822+
-- g is not allowed
1823+
SELECT regexp_match('foobarbequebazmorebarbequetoo'::citext, '(BAR)(BEQUE)'::citext, 'g') AS "error";
1824+
ERROR: regexp_match does not support the global option
1825+
HINT: Use the regexp_matches function instead.
1826+
CONTEXT: SQL function "regexp_match" statement 1
17731827
SELECT regexp_matches('foobarbequebaz'::citext, '(bar)(beque)') = ARRAY[ 'bar', 'beque' ] AS t;
17741828
t
17751829
---

contrib/citext/sql/citext.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,18 @@ SELECT md5( name ) = md5( name::text ) AS t FROM srt;
592592
SELECT quote_ident( name ) = quote_ident( name::text ) AS t FROM srt;
593593
SELECT quote_literal( name ) = quote_literal( name::text ) AS t FROM srt;
594594

595+
SELECT regexp_match('foobarbequebaz'::citext, '(bar)(beque)') = ARRAY[ 'bar', 'beque' ] AS t;
596+
SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)') = ARRAY[ 'bar', 'beque' ] AS t;
597+
SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext) = ARRAY[ 'bar', 'beque' ] AS t;
598+
SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, '') = ARRAY[ 'bar', 'beque' ] AS t;
599+
SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)', '') = ARRAY[ 'bar', 'beque' ] AS t;
600+
SELECT regexp_match('foobarbequebaz', '(BAR)(BEQUE)'::citext, '') = ARRAY[ 'bar', 'beque' ] AS t;
601+
SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, ''::citext) = ARRAY[ 'bar', 'beque' ] AS t;
602+
-- c forces case-sensitive
603+
SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, 'c'::citext) = ARRAY[ 'bar', 'beque' ] AS "no result";
604+
-- g is not allowed
605+
SELECT regexp_match('foobarbequebazmorebarbequetoo'::citext, '(BAR)(BEQUE)'::citext, 'g') AS "error";
606+
595607
SELECT regexp_matches('foobarbequebaz'::citext, '(bar)(beque)') = ARRAY[ 'bar', 'beque' ] AS t;
596608
SELECT regexp_matches('foobarbequebaz'::citext, '(BAR)(BEQUE)') = ARRAY[ 'bar', 'beque' ] AS t;
597609
SELECT regexp_matches('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext) = ARRAY[ 'bar', 'beque' ] AS t;

doc/src/sgml/citext.sgml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ SELECT * FROM users WHERE nick = 'Larry';
124124
</para>
125125

126126
<itemizedlist>
127+
<listitem>
128+
<para>
129+
<function>regexp_match()</>
130+
</para>
131+
</listitem>
127132
<listitem>
128133
<para>
129134
<function>regexp_matches()</>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy