query first time works second time fails for one connection

Lists: pgsql-bugs
From: pgsql-bugs(at)postgresql(dot)org
To: pgsql-bugs(at)postgresql(dot)org
Subject: query first time works second time fails for one connection
Date: 2001-08-01 15:31:12
Message-ID: 200108011531.f71FVC841512@hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Rahul Gade (Rahul_g(at)ip(dot)eth(dot)net) reports a bug with a severity of 2
The lower the number the more severe it is.

Short Description
query first time works second time fails for one connection

Long Description
In fact i want to execute the code which i hade placed in remark, but since the orderby, limit, desc are not supporting here.
I have choosed another option of using temp table for storing result of subquery.
This procedure is getting invoked throug the trigger before/after (both because i have tried it on both event) insert

but in the the time of insertion of data through another procedure
first time it works but for the second time it gives me error as :
ERROR: ExecOpenScanR: failed to open relation 28705

Before second time i am taking care of dropping the temp table tr3.
This command fails for second time in a single connection session but works again in the next connection session to database.

I am not getting why it is failed in second time, while it's working nice in first session.

Hello, Thats not enough, i have found another thing which seems to be a bug.
I can't use the command
drop table tablename
inside the function

I am using postgresql 7.0.2 on redhat 7

Thanks for quick response...

Except these bugs i have facinated with postgresql.It too good than other RDBMS.

Sample Code
create function funNotificationLimit() returns opaque
as
'declare serverId int;
begin
serverId=(select NEW.srvserverid);
create temp table tr as select rptreportid from reporttable
where srvserverid=serverId order by rpttimestamp desc limit 20;
delete from reporttable where srvserverid=serverId and
rptreportid<(select min(rptreportid) from tr);

/* delete from reporttable where srvserverid=serverId and
rptreportid not in(select rptreportid from reporttable
where srvserverid=serverId order by rpttimestamp desc limit 20);*/
return NEW;
end;'
language 'plpgsql';

No file was uploaded with this report


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Rahul_g(at)ip(dot)eth(dot)net, pgsql-bugs(at)postgresql(dot)org
Subject: Re: query first time works second time fails for one connection
Date: 2001-08-01 16:28:00
Message-ID: 10152.996683280@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Temp tables don't interact well with plpgsql's attempts to cache query
plans for the queries in its functions. This is a bug, but a solution
is not close at hand.

In 7.1, you can work around this by using EXECUTE to execute the queries
on the temp table, thus forcing a re-plan on every execution. Ugly but
serviceable.

Another possibility is to create the temp table only once per session,
outside the function itself. The function can just DELETE FROM the
table to clear it for re-use on each call.

regards, tom lane