473,625 Members | 3,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

function calls in WHERE clause

I have a view like this:

CREATE or replace VIEW program_member_ this_year AS
SELECT DISTINCT person.person_i d
FROM unit.person, unit.visit
WHERE
unit.person.per son_id = unit.visit.pers on_id
AND
visit.program_i d = this_program()
AND
visit.time_stam p > shared.last_sep tember();

and I would like to speed it up ...

I notice that if I write it like this:

CREATE or replace VIEW program_member_ this_year AS
SELECT DISTINCT person.person_i d
FROM unit.person, unit.visit
WHERE
unit.person.per son_id = unit.visit.pers on_id
AND
visit.program_i d = 3
AND
visit.time_stam p > '2004-9-1';

It takes about 1/4 the time as with the function calls.

Both of those function calls will always return the exact
same thing for any given query.

My approach now is to make a Pl/PgSQL function which
will build up the correct query with the function calls
replaced by their constant results .... but is there a
better way?

I should note that this_program() is defined as VOLATILE.

It was a while ago, but I believe this is because I have
a this_program() defined in each schema and they
return a different value depending on which schema
you are in when you call the function...

Thanks for any insight.

_______________ _______________ _______________ _______________ _____
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
http://join.msn.com/?page=features/virus
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 23 '05 #1
1 1573
"Lee Harr" <mi*****@hotmai l.com> writes:
I should note that this_program() is defined as VOLATILE.
So don't do that ;-)
It was a while ago, but I believe this is because I have
a this_program() defined in each schema and they
return a different value depending on which schema
you are in when you call the function...


But each one of these is individually immutable, no? If it's not,
how are you expecting your query-builder function to give the same
answers as before?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 23 '05 #2

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

Similar topics

6
14669
by: Christian | last post by:
HI, I have a function that is used to constrain a query: Select COl1, Col2 From MyTable WHERE col1 = ... AND col2 = ... And MyFunction(col1) = ... My problem is that MyFunction is executed as many times that there are
2
4425
by: Agoston Bejo | last post by:
Version: Oracle 8.1.7. (I know it's prehistoric, but I am forced to work with it. Nevertheless, I'm curious if this is only a bug of this version or I'm wrong somewhere about SQL itself.) Take a look at this query: ----------------------- SELECT * FROM (
2
2462
by: ChasW | last post by:
I just read these 2 pages. These are most helpful, but leave me with a question. http://www.mvps.org/access/queries/qry0005.htm http://www.mvps.org/access/forms/frm0007.htm I have a Multi Select Listbox that will define query criteria for a query that is the record source for another form. Certain individual selections in this list box may act a label for a
4
2660
by: Phil Latio | last post by:
I'm kind of looking for some guidance in respect of this obstacle I'm up against - please let me expand; I have an option group with three options (AND, OR, & NONE) and a text box which will accept free text - the text will become criteria in a SQL string and depending upon the option the WHERE clause will be AND/OR LIKE textCriteria1 AND/OR LIKE textCriteria2.... I'm trying to create a VBA function to take the free text and break up...
1
1643
by: dmh_test1 | last post by:
I have a view created in an adp which calls a UDF, also written in the adp, which simply contatenates some varchar fields based on some business logic and returns a varchar(50). The view looks fine in the adp, but when I link to the view from an mdb, only the first character appears. If I open the view in the mdb in design view, it shows the field as having type "text", with a fieldsize of one. Any ideas on how to get the mdb to pick up...
4
10070
by: Szymon Dembek | last post by:
Hi Recently I did some DB2 and ODBC coding in Visual FoxPro. I bumped on a problem I cannot resolve. When I issue a delete statement that deletes no rows (no rows qualify for the WHERE conditions), DB2 raises SQL0100W warning with SQLSTATE=02000. The same happens when issuing an insert with select clause (insert into .... select from ...) when no rows are fetched by the select clause.
9
3267
by: CryptiqueGuy | last post by:
Consider the variadic function with the following prototype: int foo(int num,...); Here 'num' specifies the number of arguments, and assume that all the arguments that should be passed to this function are of type int. (My question has nothing to do with the definition of the function foo, so don't bother about it.) If I call the function as: foo(2,3,4,5,6,7,8);/*More arguments than expected*/
6
21720
by: nathanM | last post by:
Hi, I have a function, looks a bit like this: def function(): if condition: do stuff, including a few recursive calls (to function()), this 'stuff' also changes the state of 'condition'. 'condition' is a global list.
14
1635
by: mesut | last post by:
hi colleagues, I don't know if this is the right group for but it's in C# so I try. I have a #3 procedural function called GetInfo.. and those are 3 overloaded methods. I would like to use the OOP approach to refactor this. The functions are working fine but I would like to have a OOP approach can someone help me refactoring this??????
0
8256
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8189
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
8694
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8356
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
8497
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4089
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4193
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2621
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
1803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.