Re: Indexes in PL/SQL - Mailing list pgsql-novice

From Joe Conway
Subject Re: Indexes in PL/SQL
Date
Msg-id 3ED77289.1090105@joeconway.com
Whole thread Raw
In response to Indexes in PL/SQL  (Tony Holmes <tony@crosswinds.net>)
List pgsql-novice
Tony Holmes wrote:
[...snip...]
> username character varying(32),
         (1)^^^^^^^^^^^^^^^^^^
[...snip...]
> CREATE FUNCTION valid_user(text) RETURNS text AS '
                           (2)^^^^
> DECLARE
>  _user ALIAS FOR $1;
>  _uid user_main.uid%TYPE;
> BEGIN
> SELECT uid INTO _uid FROM user_main WHERE username=_user;
                                          (3)^^^^^^^^^^^^^^

I think you have a character type mismatch. When you write:

   SELECT uid FROM user_main WHERE username='bob';

the constant 'bob' is initially type "unknown". Postgres is then able to
deduce that it should be varchar given the context, and therefore finds
the index. In your function, try either:

(2) CREATE FUNCTION valid_user(varchar) RETURNS text AS '

or

(3) SELECT uid INTO _uid FROM user_main WHERE username=_user::varchar;

HTH,

Joe


pgsql-novice by date:

Previous
From: Tony Holmes
Date:
Subject: Indexes in PL/SQL
Next
From: Tom Lane
Date:
Subject: Re: Indexes in PL/SQL