From: | "Victoria W(dot)" <wicki(at)terror(dot)de> |
---|---|
To: | pgsql-interfaces(at)postgresql(dot)org |
Subject: | livetime of a variable defined in a c-procedure |
Date: | 1999-06-02 05:56:07 |
Message-ID: | Pine.LNX.3.95.990602055543.12826D-100000@csb.terror.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-interfaces |
hi all,
I want to build sub-sums of an column (rechnr, for example). this field
should be incremented, whenever the field "baust" changes.
I'm able to increment a field by a function:
create function add_intsum(varchar,int8) returns int8
as' update sum_table set intsum=((intsum )+ ($2))where key1 = $1;
select max(intsum) from sum_table where key1 = $1;'
language 'sql';
sum_table ist delared as:
create table sum_table(key1 varchar,moneysum money,realsum real,intsum
int8);
insert into sum_table values('baust','0',0,0);
insert into sum_table values('contanz', '0',0,0);
insert into sum_table values('rechnr', '0',0,0);
now "select add_intsum('rechnr',1);" will increment "rechnr" in
"sum_table" and return this field. this works - but there are 2 problems:
a) its not very fast
b) I can't do a conditional-increment, depending on the value
of another field
so I've don the following:
int4 rechnr=0;
int4 baust=0;
int4 add_rechnr(int4 val)
{rechnr=rechnr+val;return rechnr;}
int4 add_baust(int4 val)
{baustelle=baust+val;return baust;}
int4 init_rechnr(int4 val)
{rechnr=val;return rechnr;}
int4 init_baust(int4 val)
{baust=val;return baust;}
this works and I'm able to include conditions into the c-code. But what I
not fully understand is the followinf behaviour:
CREATE FUNCTION add_rechnr(int4) RETURNS int4
AS '/usr/local/pgsql/lib/modules/funcs.so' LANGUAGE 'c';
whenever I add a value to rechnr, the correct result is returned. but if I
copy the save file "funcs.so" into the direcotry while the backend is
running an a connection is established, I'll get this error:
pqReadData() -- backend closed the channel unexpectedly.
.....
So I suppose, the backend will load the lib whenever a lib-function is
invoced. But if so, why does he remember the last value of the variables
defined in this lib?
Any ideas ?
best regards
wicki ;*)
From | Date | Subject | |
---|---|---|---|
Next Message | ßN·¬ | 1999-06-02 08:22:12 | problem with JDBC |
Previous Message | Victoria W. | 1999-06-02 05:53:55 | livetime of a variable defined in a c-procedure |