substr negative indexes

Поиск
Список
Период
Сортировка
От Guy Rouillier
Тема substr negative indexes
Дата
Msg-id 45AA72B2.30502@burntmail.com
обсуждение исходный текст
Ответы Re: substr negative indexes  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Michael Fuhr
Дата:
Сообщение: Re: Export to shape file
Следующее
От: "Pavan Deolasee"
Дата:
Сообщение: Re: Autovacuum Improvements