Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support POSITION(substring IN string) → integer #8938

Closed
neverchanje opened this issue Apr 3, 2023 · 1 comment · Fixed by #9000
Closed

support POSITION(substring IN string) → integer #8938

neverchanje opened this issue Apr 3, 2023 · 1 comment · Fixed by #9000
Assignees
Labels
component/func-expr Support a SQL function or operator
Milestone

Comments

@neverchanje
Copy link
Contributor

Syntax

POSITION(substring IN string) → integer

Description

The position function in Postgres is used to find the location of the
first occurrence of a specified substring within a given string. The
result is an integer representing the character position of the
substring’s first occurrence, counting from 1. If the substring is not
found, the function returns 0.

Parameters

  • substring (text): The substring to search for within the given
    string.

  • string (text): The string in which to search for the specified
    substring.

Returns

The function returns an integer value representing the position of the
first occurrence of the substring within the string, or 0 if the
substring is not found.

Examples

SELECT POSITION('world' IN 'hello world'); -- Returns 7
SELECT POSITION('abc' IN 'hello world'); -- Returns 0

In these examples, the position function finds the location of the
specified substring within the given string.

See Also

  • strpos: Finds the location of a specified substring within a given
    string.

  • substring: Extracts a substring from a given string based on a
    specified starting position and length.

  • overlay: Replaces a portion of a string with a specified
    substring.

Compatibility

The position function is compatible with PostgreSQL and is part of the
SQL standard.

@github-actions github-actions bot added this to the release-0.19 milestone Apr 3, 2023
@xiangjinwu
Copy link
Contributor

Just need to alias / bind to strpos(string, substring). Note the reversed argument order.

@xiangjinwu xiangjinwu added the component/func-expr Support a SQL function or operator label Apr 4, 2023
@xiangjinwu xiangjinwu linked a pull request Apr 4, 2023 that will close this issue
4 tasks
@xiangjinwu xiangjinwu self-assigned this Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/func-expr Support a SQL function or operator
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants