是否有任何函数可用于在 postgresql 中指定索引后查找字符串位置 [英] Is there any function available to find string position after specified index in postgresql

查看:281
本文介绍了是否有任何函数可用于在 postgresql 中指定索引后查找字符串位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Postgres 中可用的函数:

The function available in Postgres:

strpos(string, substring)

例如:

strpos('my name is database', 'm')

返回:1

我的要求是返回指定索引后子串的位置:

My requirement is to return the position of the substring after a specified index:

strpos(string, substring, 5)

例如:

strpos('my name is database', 'm', 1)

应该返回:6

推荐答案

STRPOS 只接受两个参数.但是您可以将调用链接到 substring 并轻松实现您的目标.

STRPOS accepts only two arguments. But you can chain a call to substring and easily achieve your objective.

SELECT STRPOS(SUBSTRING('my name is database',2), 'm')

请注意,postgresql 字符串从 1 开始而不是 0,因此您必须在上述查询中输入 2 而不是 1.当然,结果是相对于新字符串 'y name is database' 而言的,因此您必须在结果中加 1.

Note that postgresql strings start from 1 and not 0 so you have to put 2 instead of 1 in the above query. Of course the result is relative to the new string 'y name is database' so you will have to add 1 to the result.

这篇关于是否有任何函数可用于在 postgresql 中指定索引后查找字符串位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆