From: | Jaime Casanova <systemguards(at)yahoo(dot)com> |
---|---|
To: | Eric Aponte <eaponte(at)usb(dot)ve> |
Cc: | pgsql-es-ayuda(at)postgresql(dot)org |
Subject: | Re: Columnas afectadas en Postgresql |
Date: | 2004-07-22 21:41:07 |
Message-ID: | 20040722214107.71464.qmail@web50008.mail.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
Hi Eric,
Puedes intentar esto en la funcion en la que deseas
saber si existe el registro:
perform select * from mitabla;
if found then
existe, haz esto;
else
no existe, haz lo otro;
end if;
Atentamente,
Anl. Jaime Casanova
Asesor de Sistemas - Diteca
--- Eric Aponte <eaponte(at)usb(dot)ve> escribió: > Eso es lo
que espero, pero yo le estoy mandando un
> select ya que
> necesito saber si el registro existe en la base de
> datos, si existe hago
> una operacion y sino hago otra, voy a seguir
> intentando, muchas gracias
>
> Jaime Casanova escribió:
>
> > Hi Eric,
> >
> > Tengo esto hecho:
> >
> > CREATE TABLE tmp_prueba (
> > col1 integer
> > );
> >
> > insert into tmp_prueba values (1);
> > insert into tmp_prueba values (2);
> > insert into tmp_prueba values (3);
> > insert into tmp_prueba values (4);
> > insert into tmp_prueba values (5);
> >
> > CREATE OR REPLACE FUNCTION tmp_query (varchar)
> RETURNS numeric AS'
> > declare
> > var_sw numeric;
> > registros numeric;
> > begin
> > execute $1;
> > get diagnostics registros = row_count;
> > if registros = 1 then
> > var_sw := 1;
> > else
> > var_sw := 0;
> > end if;
> > return var_sw;
> > end;
> > 'LANGUAGE 'plpgsql';
> >
> > select tmp_query('update tmp_prueba set col1 =
> col1 + 1 where col1 > 3');
> > Cuando lo ejecuto: la funcion me devuelve cero
> porque se afectaron
> > varias filas (2)
> >
> > Y si hago
> > select tmp_query('update tmp_prueba set col1 =
> col1 + 1 where col1 < 2');
> > la funcion me devuelve 1 porque se afecta 1 sola
> fila, eso es lo que
> > la funcion dice que hace.
> >
> > Ese es el comportamiento correcto o esperabas otra
> cosa?
> >
> > Atentamente,
> > Jaime Casanova
> >
> >
> > Eric Aponte <eaponte(at)usb(dot)ve> wrote:
> >
> > Hice los cambios, pero no le asigna valor a la
> variable registros
> >
> > CREATE OR REPLACE FUNCTION query (text)
> RETURNS numeric AS'
> >
> > declare
> > var_sw numeric;
> > registros integer;
> > begin
> > execute $1;
> > get diagnostics registros = row_count;
> > if registros > 0 then
> > var_sw := 1;
> > else
> > var_sw := 0;
> > end if;
> > return var_sw;
> > end;
> > 'LANGUAGE 'plpgsql';
> >
> > Gracias
> >
> >
> >
>
------------------------------------------------------------------------
> > Do You Yahoo!?
> >
>
<http://espanol.yahoo.com/mail_tagline/*http://espanol.news.yahoo.com>
>
> > Todo lo que quieres saber de Estados Unidos,
> América Latina y el resto
> > del Mundo.
> > Visíta Yahoo! Noticias
> >
>
<http://espanol.yahoo.com/mail_tagline/*http://espanol.news.yahoo.com>.
>
>
>
_________________________________________________________
Do You Yahoo!?
Información de Estados Unidos y América Latina, en Yahoo! Noticias.
Visítanos en http://noticias.espanol.yahoo.com
From | Date | Subject | |
---|---|---|---|
Next Message | JimAlexandr | 2004-07-22 22:15:15 | consulta - herramienta olap |
Previous Message | Alvaro Herrera | 2004-07-22 20:47:40 | Re: Problemas con delete |