实现这一点有两种方法,示例如下:
postgres=# select strpos('W3Schools.com','Schools');
strpos
--------
3
(1 row)
postgres=# select position('Schools' in 'W3Schools.com');
position
----------
3
(1 row)
postgres=# select regexp_matches('hahahabc123zzz', '(abc)(123)');
regexp_matches
----------------
{abc,123}
postgres=# select array_to_string(regexp_matches('hahahabc123zzz', '(abc)(123)'),' ');
array_to_string
-----------------
abc 123
postgres=# select (regexp_matches('hahahabc123zzz', '(abc)(123)'))[1] as a, (regexp_matches('hahahabc123zzz', '(abc)(123)'))[2] as b;
a | b
-----+-----
abc | 123
(1 row)
你想要这个吗?
您可以在这里得到字符串过程的所有函数:
https://www.postgresql.org/docs/10/functions-string.html