473,651 Members | 2,580 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Temporary views

Currently you can create temporary tables that are deleted at the end of the
session. But how about temporary views? It's just a table with a rule so I
don't imagine it would be terribly difficult. Are there any issues I havn't
thought of?

While we're at it, what about temporary functions?
--
Martijn van Oosterhout <kl*****@svana. org> http://svana.org/kleptog/
(... have gone from d-i being barely usable even by its developers
anywhere, to being about 20% done. Sweet. And the last 80% usually takes
20% of the time, too, right?) -- Anthony Towns, debian-devel-announce


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFAKWatY5T wig3Ge+YRAmMoAK DHapDC20edFd9xh ss9K5SJ1fnUzACZ AaQo
r+9fYtLgTlivGLn yfuNEOP4=
=JLwn
-----END PGP SIGNATURE-----

Nov 22 '05 #1
8 2007
Martijn van Oosterhout <kl*****@svana. org> writes:
Currently you can create temporary tables that are deleted at the end of the
session. But how about temporary views? It's just a table with a rule so I
don't imagine it would be terribly difficult. Are there any issues I havn't
thought of? While we're at it, what about temporary functions?


AFAICS, anything created in the temp schema will get zapped at backend
shutdown. (It would be a good idea to rename RemoveTempRelat ions and
related functions in namespace.c if they are going to be used to zap
other sorts of objects, but they will work as-is.)

So this is doable with just a Small Matter of Programming to pass the
is-temp flag through from the grammar to wherever the object gets
created.

Whether it's worth the trouble is another question. What's the
use-case?

regards, tom lane

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

Nov 22 '05 #2
On Wed, Feb 11, 2004 at 12:10:29AM -0500, Tom Lane wrote:
Martijn van Oosterhout <kl*****@svana. org> writes:
Currently you can create temporary tables that are deleted at the end of the
session. But how about temporary views? It's just a table with a rule so I
don't imagine it would be terribly difficult. Are there any issues I havn't
thought of?
While we're at it, what about temporary functions?


AFAICS, anything created in the temp schema will get zapped at backend
shutdown. (It would be a good idea to rename RemoveTempRelat ions and
related functions in namespace.c if they are going to be used to zap
other sorts of objects, but they will work as-is.)

So this is doable with just a Small Matter of Programming to pass the
is-temp flag through from the grammar to wherever the object gets
created.


Well, the rules should disappear with the table, so I guess everything
should be fine in that respect.
Whether it's worth the trouble is another question. What's the
use-case?
Oh, I have a script which executes lots of queries which use several similar
rather complicated subqueries. By encapsulating these subqueries into views
all these queries could be simplified. The subqueries are not identical
between runs, though they are the same within a run.

The subqueries are not used elsewhere in the system and I'd feel better if
the definitions were near the code that used them rather than permanently in
the database where they are just clutter.

The workaround ofcourse is to do:

DROP VIEW x; -- might error
CREATE VIEW x AS ...

.... run script ...

DROP VIEW x;

and just hope no-one use the same view/table name elsewhere. It just
occurred to me that this is precisely the problem temp tables solve.

Essentially I'm using views for macro expansion.

Think it's worth it?
--
Martijn van Oosterhout <kl*****@svana. org> http://svana.org/kleptog/ (... have gone from d-i being barely usable even by its developers
anywhere, to being about 20% done. Sweet. And the last 80% usually takes
20% of the time, too, right?) -- Anthony Towns, debian-devel-announce


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFAKb4MY5T wig3Ge+YRAvUWAK DJVXyjOcIyrRM2v bQ32T4687txuwCg p/vw
Nd6ZT17Ehqmbb3i fvHAitwM=
=00Ix
-----END PGP SIGNATURE-----

Nov 22 '05 #3
Martijn van Oosterhout <kl*****@svana. org> writes:
On Wed, Feb 11, 2004 at 12:10:29AM -0500, Tom Lane wrote:
So this is doable with just a Small Matter of Programming to pass the
is-temp flag through from the grammar to wherever the object gets
created.
...
Whether it's worth the trouble is another question. What's the
use-case?
[ example snipped ]
Essentially I'm using views for macro expansion. Think it's worth it?


If you want to submit a patch I won't stand in your way. How bad is
your itch?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 22 '05 #4
The world rejoiced as tg*@sss.pgh.pa. us (Tom Lane) wrote:
Martijn van Oosterhout <kl*****@svana. org> writes:
Currently you can create temporary tables that are deleted at the
end of the session. But how about temporary views? It's just a
table with a rule so I don't imagine it would be terribly
difficult. Are there any issues I havn't thought of?

While we're at it, what about temporary functions?


AFAICS, anything created in the temp schema will get zapped at
backend shutdown. (It would be a good idea to rename
RemoveTempRelat ions and related functions in namespace.c if they are
going to be used to zap other sorts of objects, but they will work
as-is.)

So this is doable with just a Small Matter of Programming to pass
the is-temp flag through from the grammar to wherever the object
gets created.

Whether it's worth the trouble is another question. What's the
use-case?


It's where you create a temporary table to store some results, but
then want to create a view on top of that, because that makes some
funky self-join more convenient.

I found myself wanting this very thing last night when generating a
report. (Believe it or not!)
--
"cbbrowne","@", "ntlug.org"
http://www3.sympatico.ca/cbbrowne/spreadsheets.html
"It seems that perfection is attained not when nothing is left to add,
but when nothing is left to be taken away."
-- Antoine de Saint-Exupery.
Nov 22 '05 #5
>> While we're at it, what about temporary functions?
....
Whether it's worth the trouble is another question. What's the
use-case?


I have a data-loading script that transforms data from an intermediate
form in work tables to its final resting place in production. Part of this
is a major string processing step that's pushed into a stored procedure
temporarily to eliminate something on the order of a million round-trips
in trivial query overhead every night. (For each of ~320,000 records,
split a string into individual items and synchronize the detail table;
repeat for four sets of input data.)

I don't find lack of temporary functions to be a hindrance. Perhaps it's a
nice double-check for cleaning up when something goes wrong, but in that
case, I'm likely to want things left behind for debugging, but the
function creation is probably going to be rolled back anyhow.

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 22 '05 #6
On Wed, Feb 11, 2004 at 09:47:54AM -0600, Arthur Ward wrote:
While we're at it, what about temporary functions?
...
Whether it's worth the trouble is another question. What's the
use-case?


...

I don't find lack of temporary functions to be a hindrance. Perhaps it's a
nice double-check for cleaning up when something goes wrong, but in that
case, I'm likely to want things left behind for debugging, but the
function creation is probably going to be rolled back anyhow.


<Light goes on> Of course, all in one transaction. VIEW deleted on rollback
anyway.

You're right, rollback applies to anything, so this is not a really big
deal.
--
Martijn van Oosterhout <kl*****@svana. org> http://svana.org/kleptog/ (... have gone from d-i being barely usable even by its developers
anywhere, to being about 20% done. Sweet. And the last 80% usually takes
20% of the time, too, right?) -- Anthony Towns, debian-devel-announce


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFAKo6wY5T wig3Ge+YRAtJ5AK CZncDXbBzloY7Xi tAbbl/U092nJgCfZDGB
jskJkJ9bV3Fl0s8 SHrhux8I=
=Yk9t
-----END PGP SIGNATURE-----

Nov 22 '05 #7
Christopher Browne <cb******@acm.o rg> writes:
Whether it's worth the trouble is another question. What's the
use-case?
It's where you create a temporary table to store some results, but
then want to create a view on top of that, because that makes some
funky self-join more convenient. I found myself wanting this very thing last night when generating a
report. (Believe it or not!)


Hmm. Interestingly enough, you can do that right now (in 7.3 or later):

regression=# create temp table foo as select * from int8_tbl;
SELECT
regression=# create view v as select * from foo;
CREATE VIEW
regression=# \c -
You are now connected to database "regression ".
regression=# \dv v
No matching relations found.

The view goes away at backend exit because it has a dependency on foo.

Whether this is really desirable or not, I'm not sure. It would
probably be better if you'd had to say "create temp table v", just
to avoid surprises.

regards, tom lane

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

Nov 22 '05 #8
Tom Lane wrote:
Christopher Browne <cb******@acm.o rg> writes:
Whether it's worth the trouble is another question. What's the
use-case?

It's where you create a temporary table to store some results, but
then want to create a view on top of that, because that makes some
funky self-join more convenient.

I found myself wanting this very thing last night when generating a
report. (Believe it or not!)


Hmm. Interestingly enough, you can do that right now (in 7.3 or later):

regression=# create temp table foo as select * from int8_tbl;
SELECT
regression=# create view v as select * from foo;
CREATE VIEW
regression=# \c -
You are now connected to database "regression ".
regression=# \dv v
No matching relations found.

The view goes away at backend exit because it has a dependency on foo.

Whether this is really desirable or not, I'm not sure. It would
probably be better if you'd had to say "create temp table v", just
to avoid surprises.


TODO has:

* Have views on temporary tables exist in the temporary
namespace

One thing we don't have is the ability to create a temp view on a real
table, which we don't support right now.

I have added this to TODO:

* Allow temporary views on non-temporary tables

--
Bruce Momjian | http://candle.pha.pa.us
pg***@candle.ph a.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 22 '05 #9

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

Similar topics

11
16289
by: randi_clausen | last post by:
Using SQL against a DB2 table the 'with' key word is used to dynamically create a temporary table with an SQL statement that is retained for the duration of that SQL statement. What is the equivalent to the SQL 'with' using TSQL? If there is not one, what is the TSQL solution to creating a temporary table that is associated with an SQL statement? Examples would be appreciated. Thank you!!
4
12039
by: prasad | last post by:
I am getting sql error during binding a program which access a temporary table. The temporary table declaration and access methods are given below. EXEC SQL DECLARE GLOBAL TEMPORARY TABLE TEM88 LIKE SYSIBM.SYSDUMMY1 END-EXEC. EXEC SQL INSERT INTO TEM88 SELECT * FROM SYSIBM.SYSDUMMY1 END-EXEC.
4
4763
by: zbychu | last post by:
Hi Db2UDB version 8.2 Is possible difrent way than this DECLARE TT as select * from session.TT definition only;
3
10168
by: KemperR | last post by:
Hello Experts outhere, may be someone can tell me whats going wrong with my ADOX trial. I have an Access 2002 database with some tables and queries (views) The code listed below works well up to the point where I want to add the new view to the views collection. I get Runtime error 3001 which is telling me "Arguments are of wrong type,are out of acceptable range or conflict with one another"
2
1948
by: dbuchanan52 | last post by:
Hello, I am building an application for Windows Forms using. I am new to SQL Server 'Views'. Are the following correct understanding of their use? 1.) I believe a view can be referenced in a stored procedure something like this; Select * from View1 Is that true?
15
3063
by: rod.weir | last post by:
Fellow database developers, I would like to draw on your experience with views. I have a database that includes many views. Sometimes, views contains other views, and those views in turn may contain views. In fact, I have some views in my database that are a product of nested views of up to 6 levels deep! The reason we did this was. 1. Object-oriented in nature. Makes it easy to work with them.
33
6648
by: Peter | last post by:
People are telling me it is bad to put select * from <atable> in a view. I better should list all fields of the table inside the definition of the view. I dont know exactly why but some say: A select * from makes sql server does a table scan.
7
4653
by: Gary | last post by:
Hello guys! Bear with me, I am a newbie. She is the Data Warehouse manager. She has about 50 users to use the Oracle database from M$ Access via ODBC connection. All those users have only SELECT privileges on certain tables. I built all the roles and users for them and they work fine. Then she asked "Why do YOU let them see all those system tables?",
6
3291
by: Troels Arvin | last post by:
Hello, I have recently run a rather large data import where the imported data i pumped through some updatable views equipped with INSTEAD OF triggers. For various reasons, the exact same data where imported into the exact same table/view/trigger structures (but with slightly different tablespace configuration, see later). The involved hardware was different (one running on x86_64, one running on PPC), but with comparable CPU, memory and...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8695
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8460
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7296
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1906
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.