Creating SQL functions - Mailing list pgsql-general

From Erich
Subject Creating SQL functions
Date
Msg-id 200009122355.QAA27944@cyberpass.net
Whole thread Raw
List pgsql-general
I'm trying to create a function like this:

CREATE FUNCTION usercolor (INT)
    RETURNS INT
    AS 'SELECT color
        FROM users
        WHERE number = $1
        ORDER BY time
        LIMIT 1'
        LANGUAGE 'sql';

and it doesn't work.  It gives me an error that the return type is
INT, but the SELECT statement might return more than one value.  Well,
it can only return one value because of the LIMIT 1.  What's the best
way to do this kind of thing?  Is this a bug in Postgres?

Thanks,

e

pgsql-general by date:

Previous
From: Erich
Date:
Subject: Contract for adding replication support to Postgres
Next
From: Oleg Bartunov
Date:
Subject: Re: [SQL] Weighted Searching