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

From: 100(dot)179370(at)germanynet(dot)de (Martin Jacobs)
To: pgsql-general(at)hub(dot)org
Subject: Re: Newbie, Howto access Array-Slots in user defined functions?
Date: 2000-10-06 17:04:02
Message-ID: m13haug-000QZZC@Schnecke.Windsbach.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Len,

Len Morgan schrieb:
> >
> > SELECT DISTINCT c FROM table;
> >
> >I get
> >
> >ERROR: There is no operator '<' for types '_bytea' and '_bytea'
> > You will either have to retype this query using an explicit cast,
> > or you will have to define the operator using CREATE OPERATOR
> >
> >To create an operator I need a function, so let's beginn with a
> >compare function:
> >
> > CREATE FUNCTION lessbyte (_bytea, _bytea) RETURNS bool AS
> > 'SELECT $1[1] < $[2];' LANGUAGE 'sql';

Sorry, this is a typo, my code example looks like this:

CREATE FUNCTION lessbyte (_bytea, _bytea) RETURNS bool AS
'SELECT $1[1] < $2[1];' LANGUAGE 'sql';

Ok, this is not the complete code. To do a compare of all array
elements I have to add more comparison operations. This example
is the smallest code fragment to point out my problem.

The question at this point is, how is the syntax to access an
array element of a $n-Variable which refers to an array element?
PostgreSQL does prefex the type with an underscore to make it an
array reference, but how to access a dedicated elment, also
called slot?

Any ideas?

>
>
> Shouldn't the above be:
> SELECT $1[1] < $1[2] ?
>
> You probably need the field reference in both places. I have never used
> arrays so I don't know if I'm way off base but it seems logical.
> ...
>
> >
> >I get
> >
> > ERROR: parser: parse error at or near "["
> >
> >Any hint, how to overcome this?
> ...

--
Martin Jacobs * Windsbach * 100(dot)179370(at)germanynet(dot)de und
martin(dot)jacobs(at)an-netz(dot)de
Registered Linux User #87175

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adam Lang 2000-10-06 17:05:03 Image storing
Previous Message Andy Corteen 2000-10-06 16:56:02 SQL CONNECT BY statement