Search Postgresql Archives

substr negative indexes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux