Re: [SQL] PLpgSQL variables persistance between several functions calls

2011-05-03 Thread Willy-Bas Loos
Hi,
Maybe calling a function from within another function would be a solution to
you.

Cheers,

WBL

On Tue, May 3, 2011 at 4:10 AM, Pavel Stehule wrote:

> Hello
>
> no, it's not possible
>
> Regards
>
> Pavel Stehule
>
> 2011/5/2 Charles N. Charotti :
> > Hello everybody !
> >
> > I want to know if I could share PLpgSQL variables between different
> > functions and within different calls just using memory (not tables or
> other
> > methods).
> >
> > If it is really possible ?
> >
> > Thanks in advance,
> >
> > Chuck
> >
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>



-- 
"Patriotism is the conviction that your country is superior to all others
because you were born in it." -- George Bernard Shaw


[SQL] number of values updated per column

2013-01-17 Thread Willy-Bas Loos
Hi,

I'd like to know, per column, how many values were changed by my query.
I have a working example, but i am curious what you people think about it.
Is it efficient? I have to make a self join, but i don't see a faster way.


Here's the example:
-
drop table if exists tab1 ;
create table tab1(id serial primary key, a integer, b integer, c integer);
insert into tab1 (a,b,c)
select x*random(), x*random(), x*random()
from generate_series(0,100)  foo(x);

with foo as (
update tab1 set
a=case when tab1.a >= 60 then -1 else tab1.a end
, b=case when tab1.b >= 60 then -1 else tab1.b end
, c=case when tab1.c >= 60 then -1 else tab1.c end
from tab1 old
where old.id=tab1.id
returning
case when tab1.a != old.a then 1 else 0 end as a_upd
, case when tab1.b != old.b then 1 else 0 end as b_upd
, case when tab1.c != old.c then 1 else 0 end as c_upd
)
select 'a' as fieldname, sum(a_upd) as updates from foo
union all
select 'b' as fieldname, sum(b_upd) as updates from foo
union all
select 'c' as fieldname, sum(c_upd) as updates from foo
-

Cheers,

WBL
-- 
"Quality comes from focus and clarity of purpose" -- Mark Shuttleworth