crate/crate

Add `regexp_match` scalar

Open

#15,117 创建于 2023年11月29日

在 GitHub 查看
 (3 评论) (2 反应) (0 负责人)Java (3,863 star) (545 fork)batch import
complexity: no estimatecontributions welcomefeature: sql: scalarsgood first issue

描述

Problem Statement

CrateDB contains a regexp_matches table function, but for some use cases a regular scalar would be the better fit. One use-case is using them in generated columns, where table functions cannot be used.

From https://github.com/crate/crate/issues/15077:

CREATE TABLE hernan.test  (
	a TEXT,
	b ARRAY(TEXT) GENERATED ALWAYS AS regexp_match(a, '(a(.+)z)')
	);
	
INSERT INTO hernan.test (a) 
SELECT 'alcatraz';

Possible Solutions

PostgreSQL provides a regexp_match scalar. See https://www.postgresql.org/docs/16/functions-string.html

regexp_match ( string text, pattern text [, flags text ] ) → text[]

Returns substrings within the first match of the POSIX regular expression pattern to the string; see Section 9.7.3.

regexp_match('foobarbequebaz', '(bar)(beque)') → {bar,beque}

See: https://github.com/crate/crate/blob/ff1e7f7b882f1048be6d7806023674703cc2720a/server/src/main/java/io/crate/expression/tablefunctions/MatchesFunction.java#L54 for the current regexp_matches implementation. The main difference is the support for the global (g) flag, that can result in more than one result.

贡献者指南

Add `regexp_match` scalar · crate/crate#15117 | Good First Issue