Re: Procedimiento almacenado

From: Jaime Casanova <jcasanov(at)systemguards(dot)com(dot)ec>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: Desarrollo Escuintla <desarrollo(dot)escuintla(at)gmail(dot)com>, pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: Procedimiento almacenado
Date: 2010-02-22 18:57:14
Message-ID: 3073cc9b1002221057q4e7c7a07u68ed20409258410a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

2010/2/18 Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>:
>
> Esta función se puede escribir en lenguaje sql en lugar de plpgsql.  Por
> ej.
>
> create or replace function verificaclave_1_o_0(uname text, pass text)
>  returns int language sql as
>  $$
>   select case when password = $2 then 1 else 0 end
>     from usuario
>    where username = $1;
>  $$;
>

Agrega un coalesce para evitar que regrese NULL:

select coalesce(
(select case when password = $2 then 1 else 0 end
from usuario
where username = $1), 0);

--
Atentamente,
Jaime Casanova
Soporte y capacitación de PostgreSQL
Asesoría y desarrollo de sistemas
Guayaquil - Ecuador
Cel. +59387171157

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Jaime Mendieta 2010-02-23 01:42:30 BUG #5341: problema al iniciar pgadmin
Previous Message Jose Luis Balle 2010-02-22 16:27:10 Fwd: FW: Necesito que me ayudes con esta cadena.