starts_with()

一个确定字符串是否以特定前缀开头的函数

starts_with() 是一个系统函数,用于确定提供的字符串是否以指定的字符串作为前缀。

starts_with()PostgreSQL 11 中添加。

用法

starts_with ( string text, prefix text ) → boolean

运算符 ^@ 等同于 starts_with()

请注意,没有对应的 ends_with() 函数。

替代

以下语句在功能上等同于 starts_with(),并且适用于 PostgreSQL 10 及更早版本。

SELECT TRUE WHERE string LIKE 'foo%'

变更历史

示例

starts_with() 的基本执行示例

postgres=# SELECT starts_with('foobar', 'foo');
 starts_with 
-------------
 t
(1 row)

如果提供的字符串不是以指定前缀开头,starts_with() 将返回 FALSE

postgres=# SELECT starts_with('foobar', 'bar');
 starts_with 
-------------
 f
(1 row)

运算符 ^@ 等同于 starts_with()

postgres=# SELECT 'foobar' ^@ 'foo';
 ?column? 
----------
 t
(1 row)

分类

字符串操作, 系统函数

反馈

请在此处 提交关于 “starts_with()” 的任何评论、建议或更正