starts_with() 是一个系统函数,用于确定提供的字符串是否以指定的字符串作为前缀。
starts_with() 于 PostgreSQL 11 中添加。
用法
starts_with (stringtext,prefixtext) →boolean
运算符 ^@ 等同于 starts_with()。
请注意,没有对应的 ends_with() 函数。
替代
以下语句在功能上等同于 starts_with(),并且适用于 PostgreSQL 10 及更早版本。
SELECT TRUE WHERE string LIKE 'foo%'
变更历史
- PostgreSQL 11
- 添加 (提交 710d90da)
示例
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)
参考资料
- PostgreSQL 文档: 其他字符串函数
反馈
请在此处 提交关于 “starts_with()” 的任何评论、建议或更正。