| От | Steve Crawford |
|---|---|
| Тема | Re: Return last value in of array (PostgreSQL 7.2.1) |
| Дата | |
| Msg-id | 200309231746.13757.scrawford@pinpointresearch.com обсуждение |
| Ответ на | Return last value in of array (PostgreSQL 7.2.1) (Erwin Brandstetter <Brsaz@gmzx.at>) |
| Список | pgsql-admin |
> I can't believe I have found a good solution here. I want to return
> the last value of an array with an SQL statement...
> That is what i came up with:
>
> select my_array_field[substr(array_dims(my_array_field), 4, 1)]
> from my_table;
>
> But this only works, as long as the upper boundary is from 1 to 9
> (one digit). Besides it looks ugly and will perform likewise.
>
> Did I miss something here?
> Is there any function returning more sensible data than array_dims
> (returning something like '[1:4]')?
IIRC I heard talk of new max and min array dimension functions in
upcoming releases. I'm tired so there may be better or more elegant
solutions but this one works (r is the array):
r[rtrim(substring(array_dims(r), position(':' in
array_dims(r))+1),']')::int]
Cheers,
Steve
В списке pgsql-admin по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера