Re: Newbie, Howto access Array-Slots in user defined functions?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Newbie, Howto access Array-Slots in user defined functions?
Дата
Msg-id 18185.970892876@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Newbie, Howto access Array-Slots in user defined functions?  (100.179370@germanynet.de (Martin Jacobs))
Ответы Re: Newbie, Howto access Array-Slots in user defined functions?  (100.179370@germanynet.de (Martin Jacobs))
Список pgsql-general
100.179370@germanynet.de (Martin Jacobs) writes:
>     CREATE FUNCTION lessbyte (_bytea, _bytea) RETURNS bool AS
>     'SELECT $1[1] < $2[1];' LANGUAGE 'sql';
> ERROR:  Unable to identify an operator '<' for types 'bytea' and 'bytea'
>         You will have to retype this query using an explicit cast

There is nothing wrong with your syntax --- you've declared a function
that takes two arrays of bytea, selects the first element of each, and
compares 'em.  But bytea doesn't support comparison operators ... or
much of anything, actually.  There is a get_byte function, so you could
conceivably build what you want starting with

create function lessbyte(bytea, bytea) returns bool as
'select get_byte($1,0) < get_byte($2,0)' language 'sql';

However, I don't see any reasonable way to deal with variable-length
inputs without a loop, and SQL functions don't have looping constructs.

Given the lack of operators, type bytea isn't currently useful for
much except plain storage and retrieval of raw byte sequences.
Have you got a strong reason for using bytea, rather than some
better-supported type like text?  Heck, even array of char would
work better:

regression=# CREATE FUNCTION lessbyte(_char, _char) returns bool as
regression-# 'SELECT $1[1] < $2[1];' LANGUAGE 'sql';
CREATE

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От:
Дата:
Сообщение: Re: Re: URL Type
Следующее
От: Michael Meskes
Дата:
Сообщение: Re: Using UnixODBC and postgresql