Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 字符串中第一个非数字字符的位置_Postgresql - Fatal编程技术网

Postgresql 字符串中第一个非数字字符的位置

Postgresql 字符串中第一个非数字字符的位置,postgresql,Postgresql,如何找到字符串中第一个非数字字符的位置 函数position似乎不支持正则表达式函数position不支持正则表达式,因此您应该编写稍微复杂一点的表达式,或者您可以编写自己的函数 CREATE OR REPLACE FUNCTION public.regexp_position(text, text) RETURNS integer LANGUAGE sql IMMUTABLE STRICT AS $function$ SELECT position((regexp_match($1, $

如何找到字符串中第一个非数字字符的位置


函数position似乎不支持正则表达式

函数
position
不支持正则表达式,因此您应该编写稍微复杂一点的表达式,或者您可以编写自己的函数

CREATE OR REPLACE FUNCTION public.regexp_position(text, text)
 RETURNS integer
 LANGUAGE sql
 IMMUTABLE STRICT
AS $function$
SELECT position((regexp_match($1, $2))[1] IN $1)
$function$

postgres=# select regexp_position('abcdef123','\d');
┌─────────────────┐
│ regexp_position │
╞═════════════════╡
│               7 │
└─────────────────┘
(1 row)

postgres=# select regexp_position('772727a','[^\d]');
┌─────────────────┐
│ regexp_position │
╞═════════════════╡
│               7 │
└─────────────────┘
(1 row)