livetime of a variable defined in a c-procedure (fwd)

From: "Victoria W(dot)" <wicki(at)terror(dot)de>
To: pgsql-hackers(at)postgreSQL(dot)org
Subject: livetime of a variable defined in a c-procedure (fwd)
Date: 1999-06-05 07:01:11
Message-ID: Pine.LNX.3.95.990605065758.21539A-100000@csb.terror.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

hi all,

I want to build subsubtotals of a 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 done 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 a new file "funcs.so" into the direcotry while the backend is
running and 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 hints ?

best regards

wicki ;*)

Browse pgsql-hackers by date

  From Date Subject
Next Message The Hermit Hacker 1999-06-05 14:02:44 Re: [HACKERS] PostgreSQL History(Parody)
Previous Message Kaare Rasmussen 1999-06-05 06:58:05 Re: [HACKERS] Outer joins