pg.ddx.io pgsql-docs@postgresql.org mailing list archive
help / color / mirror / Atom feedSplit_Part w/negative integer does not work
3+ messages / 3 participants
[nested] [flat]
* Split_Part w/negative integer does not work
@ 2023-03-24 20:45 PG Doc comments form <noreply@postgresql.org>
0 siblings, 2 replies; 3+ messages in thread
From: PG Doc comments form @ 2023-03-24 20:45 UTC (permalink / raw)
To: pgsql-docs@lists.postgresql.org; +Cc: spamsacrime@gmail.com
The following documentation comment has been logged on the website:
Page: https://www.postgresql.org/docs/15/functions-string.html
Description:
When n is negative, an error occurs.
Documentation
split_part ( string text, delimiter text, n integer ) → text
Splits string at occurrences of delimiter and returns the n'th field
(counting from one), or when n is negative, returns the |n|'th-from-last
field.
split_part('abc~@~def~@~ghi', '~@~', 2) → def
split_part('abc,def,ghi,jkl', ',', -2) → ghi
Observation
SELECT split_part('abc,def,ghi,jkl', ',', -1);
generates
ERROR: field position must be greater than zero
SQL state: 22023
Or in code
DO $$
DECLARE
mytxt text;
BEGIN
mytxt = split_part('abc,def,ghi,jkl', ',', -1);
RAISE NOTICE '%', mytxt;
END $$
ERROR: field position must be greater than zero
CONTEXT: SQL statement "SELECT split_part('abc,def,ghi,jkl', ',', -1)"
PL/pgSQL function inline_code_block line 6 at assignment
SQL state: 22023
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Split_Part w/negative integer does not work
@ 2023-03-25 16:48 Erik Wienhold <ewie@ewie.name>
parent: PG Doc comments form <noreply@postgresql.org>
1 sibling, 0 replies; 3+ messages in thread
From: Erik Wienhold @ 2023-03-25 16:48 UTC (permalink / raw)
To: spamsacrime@gmail.com; pgsql-docs@lists.postgresql.org
> On 24/03/2023 21:45 CET PG Doc comments form <noreply@postgresql.org> wrote:
>
> The following documentation comment has been logged on the website:
>
> Page: https://www.postgresql.org/docs/15/functions-string.html
> Description:
>
> When n is negative, an error occurs.
>
> Documentation
> split_part ( string text, delimiter text, n integer ) → text
> Splits string at occurrences of delimiter and returns the n'th field
> (counting from one), or when n is negative, returns the |n|'th-from-last
> field.
> split_part('abc~@~def~@~ghi', '~@~', 2) → def
> split_part('abc,def,ghi,jkl', ',', -2) → ghi
>
> Observation
> SELECT split_part('abc,def,ghi,jkl', ',', -1);
> generates
> ERROR: field position must be greater than zero
> SQL state: 22023
Works on 14 and 15. Support for negative indexes was added in 14. What
version do you use?
https://www.postgresql.org/docs/14/release-14.html#id-1.11.6.12.5.8
--
Erik
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Split_Part w/negative integer does not work
@ 2023-03-25 16:53 Tom Lane <tgl@sss.pgh.pa.us>
parent: PG Doc comments form <noreply@postgresql.org>
1 sibling, 0 replies; 3+ messages in thread
From: Tom Lane @ 2023-03-25 16:53 UTC (permalink / raw)
To: spamsacrime@gmail.com; +Cc: pgsql-docs@lists.postgresql.org
PG Doc comments form <noreply@postgresql.org> writes:
> Page: https://www.postgresql.org/docs/15/functions-string.html
> Documentation
> split_part ( string text, delimiter text, n integer ) → text
> Splits string at occurrences of delimiter and returns the n'th field
> (counting from one), or when n is negative, returns the |n|'th-from-last
> field.
> split_part('abc~@~def~@~ghi', '~@~', 2) → def
> split_part('abc,def,ghi,jkl', ',', -2) → ghi
> Observation
> SELECT split_part('abc,def,ghi,jkl', ',', -1);
> generates
> ERROR: field position must be greater than zero
> SQL state: 22023
Apparently, you are reading the v15 documentation and expecting it
to be exactly correct for some older server version. The described
behavior came in in v14.
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2023-03-25 16:53 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-03-24 20:45 Split_Part w/negative integer does not work PG Doc comments form <noreply@postgresql.org>
2023-03-25 16:48 ` Erik Wienhold <ewie@ewie.name>
2023-03-25 16:53 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox