Re: Columnas afectadas en Postgresql

Lists: pgsql-es-ayuda
From: Eric Aponte <eaponte(at)usb(dot)ve>
To: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Columnas afectadas en Postgresql
Date: 2004-07-19 16:33:08
Message-ID: 40FBF7C4.6070502@usb.ve
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-es-ayuda

Hola listeros, como estan, necesito ayuda con lo siguiente, estoy ceando
una funcion donde le mando a traves de un parametro un query que deseo
ejecutar, luego de ejecutarlo necesito saber cuantos registros afecto:

CREATE OR REPLACE FUNCTION query (varchar) RETURNS numeric AS'

declare
registros_afectados numeric;
begin

execute $1 ;

return registros_afectados
end;

'LANGUAGE 'plpgsql';

agradeceria muchisimo a quien pueda ayudarme

saludos desde Venezuela


From: "Mauricio Cisneros Aguilar" <mcisne(at)ife(dot)org(dot)mx>
To: <pgsql-es-ayuda(at)postgresql(dot)org>
Subject:
Date: 2004-07-19 17:27:19
Message-ID: 000f01c46db5$a75b4060$420a10ac@Mcisneros
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-es-ayuda

Hola a todos, alguien me podria decir para que se utiliza "Write Ahead Logging" (WAL) o donde puedo encontrar informacion relacionada?

GRACIAS


From: Leonel Nunez <postgres(at)enelserver(dot)com>
To: Mauricio Cisneros Aguilar <mcisne(at)ife(dot)org(dot)mx>
Cc: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re:
Date: 2004-07-19 18:19:24
Message-ID: 1090261164.1385.9.camel@debian.enelserver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-es-ayuda

On Mon, 2004-07-19 at 11:27, Mauricio Cisneros Aguilar wrote:
> Hola a todos, alguien me podria decir para que se utiliza "Write
> Ahead Logging" (WAL) o donde puedo encontrar informacion relacionada?
>
> GRACIAS

puedes preguntarle a google :

http://www.google.com/search?q=Write+Ahead+Logging&sourceid=firefox&start=0&start=0&ie=utf-8&oe=utf-8

o en la documentacion de PostgreSQL

http://www.postgresql.org/docs/7.4/static/wal.html

--
,''`. Leonel Nunez
: :' : http://enelserver.com
`. `' DEBIAN GNU/LINUX
`- A REAL FREE OS


From: Alvaro Herrera Munoz <alvherre(at)dcc(dot)uchile(dot)cl>
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-19 20:09:25
Message-ID: 20040719200925.GC15444@dcc.uchile.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-es-ayuda

On Mon, Jul 19, 2004 at 12:33:08PM -0400, Eric Aponte wrote:
> Hola listeros, como estan, necesito ayuda con lo siguiente, estoy ceando
> una funcion donde le mando a traves de un parametro un query que deseo
> ejecutar, luego de ejecutarlo necesito saber cuantos registros afecto:

Creo que puedes obtener esta informacion con GET DIAGNOSTICS o algo asi.

--
Alvaro Herrera (<alvherre[(at)]dcc(dot)uchile(dot)cl>)
La web junta la gente porque no importa que clase de mutante sexual seas,
tienes millones de posibles parejas. Pon "buscar gente que tengan sexo con
ciervos incendiánse", y el computador dirá "especifique el tipo de ciervo"
(Jason Alexander)


From: Jaime Casanova <systemguards(at)yahoo(dot)com>
To: Alvaro Herrera Munoz <alvherre(at)dcc(dot)uchile(dot)cl>, Eric Aponte <eaponte(at)usb(dot)ve>
Cc: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: Columnas afectadas en Postgresql
Date: 2004-07-19 22:15:43
Message-ID: 20040719221543.19969.qmail@web50007.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-es-ayuda

El comando que te interesa es:
GET DIAGNOSTICS integer_var = ROW_COUNT;

Tomado del manual de postgres:
37.6.5. Obtaining the Result Status
There are several ways to determine the effect of a
command. The first method is to use the GET
DIAGNOSTICS command, which has the form:

GET DIAGNOSTICS variable = item [ , ... ] ;

This command allows retrieval of system status
indicators. Each item is a key word identifying a
state value to be assigned to the specified variable
(which should be of the right data type to receive
it). The currently available status items are
ROW_COUNT, the number of rows processed by the last
SQL command sent down to the SQL engine, and
RESULT_OID, the OID of the last row inserted by the
most recent SQL command. Note that RESULT_OID is only
useful after an INSERT command.

An example:

GET DIAGNOSTICS integer_var = ROW_COUNT;

The second method to determine the effects of a
command is to check the special variable named FOUND,
which is of type boolean. FOUND starts out false
within each PL/pgSQL function call. It is set by each
of the following types of statements:

A SELECT INTO statement sets FOUND true if it returns
a row, false if no row is returned.


A PERFORM statement sets FOUND true if it produces
(and discards) a row, false if no row is produced.


UPDATE, INSERT, and DELETE statements set FOUND true
if at least one row is affected, false if no row is
affected.


A FETCH statement sets FOUND true if it returns a row,
false if no row is returned.

Atentamente,
Jaime Casanova

Alvaro Herrera Munoz <alvherre(at)dcc(dot)uchile(dot)cl> wrote:On
Mon, Jul 19, 2004 at 12:33:08PM -0400, Eric Aponte
wrote:
> Hola listeros, como estan, necesito ayuda con lo
siguiente, estoy ceando
> una funcion donde le mando a traves de un parametro
un query que deseo
> ejecutar, luego de ejecutarlo necesito saber cuantos
registros afecto:

Creo que puedes obtener esta informacion con GET
DIAGNOSTICS o algo asi.

--
Alvaro Herrera ()
La web junta la gente porque no importa que clase de
mutante sexual seas,
tienes millones de posibles parejas. Pon "buscar gente
que tengan sexo con
ciervos incendiánse", y el computador dirá
"especifique el tipo de ciervo"
(Jason Alexander)

---------------------------(end of
broadcast)---------------------------
TIP 8: explain analyze es tu amigo

_________________________________________________________
Do You Yahoo!?
Información de Estados Unidos y América Latina, en Yahoo! Noticias.
Visítanos en http://noticias.espanol.yahoo.com


From: Eric Aponte <eaponte(at)usb(dot)ve>
To:
Cc: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: Columnas afectadas en Postgresql
Date: 2004-07-20 19:09:05
Message-ID: 40FD6DD1.8080408@usb.ve
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-es-ayuda

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


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
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.


From: Eric Aponte <eaponte(at)usb(dot)ve>
To: Jaime Casanova <systemguards(at)yahoo(dot)com>
Cc: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: Columnas afectadas en Postgresql
Date: 2004-07-22 14:03:33
Message-ID: 40FFC935.2020500@usb.ve
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-es-ayuda

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>.


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
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: Eric Aponte <eaponte(at)usb(dot)ve>
To:
Cc: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: Columnas afectadas en Postgresql
Date: 2004-07-26 16:29:33
Message-ID: 4105316D.9030001@usb.ve
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-es-ayuda

Gracias, ya logre hacerlo, el problema era la forma como le mandaba la
instruccion ya que estaba condicionando un campo varchar, faltaban dos
comillas simples, ahora si hace lo que quiero, gracias de nuevo

Jaime Casanova escribió:

>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
>
>
>