Re: Columnas afectadas en Postgresql

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-20 21:10:15
Message-ID: 20040720211015.86019.qmail@web50008.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

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!?
Todo lo que quieres saber de Estados Unidos, América Latina y el resto del Mundo.
Visíta Yahoo! Noticias.

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Gorka 2004-07-21 06:57:29 Conexión desde Delphi a PostgreSQL
Previous Message Eric Aponte 2004-07-20 19:09:05 Re: Columnas afectadas en Postgresql