Re: Indexes in PL/SQL

From: Joe Conway <mail(at)joeconway(dot)com>
To: Tony Holmes <tony(at)crosswinds(dot)net>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Indexes in PL/SQL
Date: 2003-05-30 15:02:33
Message-ID: 3ED77289.1090105@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2003-05-30 15:16:45 Re: Indexes in PL/SQL
Previous Message Tony Holmes 2003-05-30 14:33:17 Indexes in PL/SQL