Skip to content

Commit 7bda696

Browse files
foreyesmy-ship-it
authored andcommitted
Add regexp_not_like() for orafce and fix test
1 parent 1d078e8 commit 7bda696

4 files changed

Lines changed: 72 additions & 0 deletions

File tree

gpcontrib/orafce/expected/gp_partition_by.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CREATE TABLE t3 (
99
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'str' as the Greenplum Database data distribution key for this table.
1010
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
1111
INSERT INTO t3 VALUES ('a'), ('b'), ('c');
12+
ANALYZE t3;
1213
SELECT * FROM t3 ORDER BY str;
1314
str
1415
-----
@@ -37,6 +38,7 @@ CREATE TABLE t4 (
3738
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'str' as the Greenplum Database data distribution key for this table.
3839
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
3940
INSERT INTO t4 VALUES ('a'), ('b'), ('c');
41+
ANALYZE t4;
4042
SELECT * FROM t4 ORDER BY str;
4143
str
4244
-----

gpcontrib/orafce/orafce--4.8--4.9.sql

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,37 @@ END;
175175
$$
176176
LANGUAGE plpgsql STRICT IMMUTABLE PARALLEL SAFE;
177177

178+
-- Add regexp_not_like based on regexp_like
179+
180+
-- REGEXP_NOT_LIKE( string text, pattern text) -> boolean
181+
-- If one of the param is NULL returns NULL, declared STRICT
182+
CREATE OR REPLACE FUNCTION oracle.regexp_not_like(text, text)
183+
RETURNS boolean
184+
AS $$
185+
-- Oracle default behavior is newline-sensitive,
186+
-- PostgreSQL not, so force 'p' modifier to affect
187+
-- newline-sensitivity but not ^ and $ search.
188+
SELECT CASE WHEN (count(*) > 0) THEN false ELSE true END FROM regexp_matches($1, $2, 'p');
189+
$$
190+
LANGUAGE 'sql' STRICT;
191+
192+
-- REGEXP_NOT_LIKE( string text, pattern text, flags text ) -> boolean
193+
CREATE OR REPLACE FUNCTION oracle.regexp_not_like(text, text, text)
194+
RETURNS boolean
195+
AS $$
196+
DECLARE
197+
modifiers text;
198+
BEGIN
199+
-- Only modifier can be NULL
200+
IF $1 IS NULL OR $2 IS NULL THEN
201+
RETURN NULL;
202+
END IF;
203+
modifiers := oracle.translate_oracle_modifiers($3, false);
204+
IF (regexp_matches($1, $2, modifiers))[1] IS NOT NULL THEN
205+
RETURN false;
206+
END IF;
207+
RETURN true;
208+
END;
209+
$$
210+
LANGUAGE plpgsql;
211+

gpcontrib/orafce/orafce--4.9.sql

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4012,6 +4012,40 @@ RETURNS text
40124012
AS 'MODULE_PATHNAME','orafce_textregexreplace'
40134013
LANGUAGE 'c' IMMUTABLE PARALLEL SAFE;
40144014

4015+
-- Add regexp_not_like based on regexp_like
4016+
4017+
-- REGEXP_NOT_LIKE( string text, pattern text) -> boolean
4018+
-- If one of the param is NULL returns NULL, declared STRICT
4019+
CREATE OR REPLACE FUNCTION oracle.regexp_not_like(text, text)
4020+
RETURNS boolean
4021+
AS $$
4022+
-- Oracle default behavior is newline-sensitive,
4023+
-- PostgreSQL not, so force 'p' modifier to affect
4024+
-- newline-sensitivity but not ^ and $ search.
4025+
SELECT CASE WHEN (count(*) > 0) THEN false ELSE true END FROM regexp_matches($1, $2, 'p');
4026+
$$
4027+
LANGUAGE 'sql' STRICT;
4028+
4029+
-- REGEXP_NOT_LIKE( string text, pattern text, flags text ) -> boolean
4030+
CREATE OR REPLACE FUNCTION oracle.regexp_not_like(text, text, text)
4031+
RETURNS boolean
4032+
AS $$
4033+
DECLARE
4034+
modifiers text;
4035+
BEGIN
4036+
-- Only modifier can be NULL
4037+
IF $1 IS NULL OR $2 IS NULL THEN
4038+
RETURN NULL;
4039+
END IF;
4040+
modifiers := oracle.translate_oracle_modifiers($3, false);
4041+
IF (regexp_matches($1, $2, modifiers))[1] IS NOT NULL THEN
4042+
RETURN false;
4043+
END IF;
4044+
RETURN true;
4045+
END;
4046+
$$
4047+
LANGUAGE plpgsql;
4048+
40154049
----
40164050
-- Add LEAST/GREATEST declaration to return NULL on NULL input.
40174051
-- PostgreSQL only returns NULL when all the parameters are NULL.

gpcontrib/orafce/sql/gp_partition_by.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CREATE TABLE t3 (
77
PARTITION t3_2 VALUES ('c')
88
);
99
INSERT INTO t3 VALUES ('a'), ('b'), ('c');
10+
ANALYZE t3;
1011
SELECT * FROM t3 ORDER BY str;
1112
\d+ t3
1213

@@ -18,6 +19,7 @@ CREATE TABLE t4 (
1819
PARTITION t4_2 VALUES ('c')
1920
);
2021
INSERT INTO t4 VALUES ('a'), ('b'), ('c');
22+
ANALYZE t4;
2123
SELECT * FROM t4 ORDER BY str;
2224
\d+ t4
2325

0 commit comments

Comments
 (0)