substr negative indexes - Mailing list pgsql-general

From Guy Rouillier
Subject substr negative indexes
Date
Msg-id 45AA72B2.30502@burntmail.com
Whole thread Raw
Responses Re: substr negative indexes  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Does the spec leave implementation of indexes on the substr() function
less than one undefined?  By mistake, I had a substr() invocation with
an initial index of zero (would be nice if all the computer languages of
the world could agree to a single definition.)  Oracle silently treats
this the same as 1 (one), while I just learned that PG treats indexes
less than 1 as a sliding window off the left of the string.  Oracle
defines negative indexes to mean "from the end of the string."

So, given a string "abcdefg":

Oracle substr('abcdefg', 1, 4) = 'abcd'
Oracle substr('abcdefg', 0, 4) = 'abcd'
Oracle substr('abcdefg', -1, 4) = 'd'
PG substr('abcdefg', 1, 4) = 'abcd'
PG substr('abcdefg', 0, 4) = 'abc'
PG substr('abcdefg', -1, 4) = 'ab'

--
Guy Rouillier

pgsql-general by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: Export to shape file
Next
From: "Pavan Deolasee"
Date:
Subject: Re: Autovacuum Improvements