473,396 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Function caches wrong OID of temporary table?

Dear PostgreSQL experts,

I have encountered a problem with temporary tables inside plpgsql
functions. I suspect that this is a known issue; if someone could
confirm and suggest a workaround I'd be grateful.

My function creates a couple of temporary tables, uses them, and drops
them before returning:
create temporary table s as select 123 as id;
create temporary table t ( id integer );
.....
insert into t (select id from s);
.....
drop table s;
drop table t;
return;
When I run this the first time it works as expected. When I run it a
second time I get this message:

ERROR: relation with OID 590209 does not exist
CONTEXT: PL/pgSQL function "f" line 18 at SQL statement

(Line 18 is the insert-select statement.)

I imagine that it has cached that one of the tables is object 590209,
but has not noticed that the table has been dropped and recreated before
the second invokation of the function.

I can supply a better test case if that would help.

Regards,

--Phil.

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #1
2 4301
On Wed, 2004-09-08 at 12:37, Phil Endecott wrote:
Dear PostgreSQL experts,

I have encountered a problem with temporary tables inside plpgsql
functions. I suspect that this is a known issue; if someone could
confirm and suggest a workaround I'd be grateful.

My function creates a couple of temporary tables, uses them, and drops
them before returning:
.... ERROR: relation with OID 590209 does not exist
CONTEXT: PL/pgSQL function "f" line 18 at SQL statement

(Line 18 is the insert-select statement.)

I imagine that it has cached that one of the tables is object 590209,
but has not noticed that the table has been dropped and recreated before
the second invokation of the function.


That is correct. You need to EXECUTE the command instead, so that it is
planned afresh each time it is used.

--
Oliver Elphick ol**@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
"Put on the whole armor of God, that ye may be able to
stand against the wiles of the devil."
Ephesians 6:11
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #2


Phil Endecott wrote:
Dear PostgreSQL experts,

I have encountered a problem with temporary tables inside plpgsql
functions. I suspect that this is a known issue; if someone could
confirm and suggest a workaround I'd be grateful.

My function creates a couple of temporary tables, uses them, and drops
them before returning:
create temporary table s as select 123 as id;
create temporary table t ( id integer );
....
insert into t (select id from s);
....
drop table s;
drop table t;
return;
When I run this the first time it works as expected. When I run it a
second time I get this message:

ERROR: relation with OID 590209 does not exist
CONTEXT: PL/pgSQL function "f" line 18 at SQL statement

(Line 18 is the insert-select statement.)

I imagine that it has cached that one of the tables is object 590209,
but has not noticed that the table has been dropped and recreated before
the second invokation of the function.


Your analysis is correct - Using execute is the work workaround.

While I'm all for function caching, this *feature* in the scenario above
is verging on a bug as far as I am concerned. I think that this item
should move from a "nice to have / to do" item to the bug list.

Other database systems that I have used are able to detect when a
procedure/function need recompiling and do it on the fly. If postgres
implemented this it would have another benefit. You could create objects
that reference other objects that don't yet exist (or are not yet
created) for example when applying a schema build script.

The first time the object is "used/called" it is compiled and all the
dependencies are resolved then (this is what Oracle is able to do).

Not forcing SQL developers to use DB-specific workarounds would be a
benefit too! :)

John Sidney-Woollett

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John Miles | last post by:
Hi -- This is a bit of an implementation-specific problem, but I'd like to post it here to see if there's a general answer within the auspices of the language. I'm developing a high(er)-level...
3
by: Doron | last post by:
hi, getting the following error when running the script below. it seems to me that the cursor is retrieving more then one value each loop. any idea how to fix this? error: ERROR at line 10:...
19
by: Christian Engström | last post by:
If you have a function that returns something by value, the gcc compiler (version 3.2.3 on Windows XP with MinGW) converts the returned value from the type you specify in the code, to the const...
38
by: Lasse Vågsæther Karlsen | last post by:
After working through a fair number of the challenges at www.mathschallenge.net, I noticed that some long-running functions can be helped *a lot* by caching their function results and retrieving...
8
by: Thorsten Tarrach | last post by:
Hallo, I have a strange problem: ASP.net caches my aspx pages, the code not the output. For testing is created a page and inserted the folowing into the body: <%=now.tostring%> Every time I...
2
by: perdubug | last post by:
Somebody told me that Tasking C166 C++ compiler has problems with temporary objects in function call parameters. He gave me below examples: Case 1:Wrong: rc = foo(&bar()); Case 2:Right: bar...
5
by: marcsirois | last post by:
I have an SQL Query that looks like this. I simplified it for the purpose of this example, but it's still a runnable query SELECT TOP 1 FundedPositions.PositionNumber AS , (select top 1...
4
by: zaeminkr | last post by:
I got a good answer here I have still confusing part. I have two very simple classes class DRect { private : double x0, y0, x1, y1; public : DRect(double a, double b, double c, double d) :...
3
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi... At least by the group title, this seems like a question for dotnet.framework.aspnet.caching but that group seems pretty slow. I'm trying to sort things out with a co-worker. We've got...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.