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

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

              http://archives.postgresql.org/

Reply via email to