473,395 Members | 1,411 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,395 software developers and data experts.

dynamic function question

I read the docs but I'm still a little lost as to how to do this.

I have this function which works fine.

CREATE OR REPLACE FUNCTION lookup_customer_byemail(varchar) RETURNS SETOF
customer_rec AS
'
DECLARE
r RECORD;
in_email ALIAS FOR $1;
BEGIN
FOR r IN SELECT
s_oid,mer_id,site_id,order_id,pymt_type,pymt_subty pe,comp_name,f_name1,l_nam
e1,f_name2,l_name2,address,city,state
,zipcode,phone,cust_email,country from customers where cust_email ILIKE
in_email LOOP
RETURN NEXT r;
END LOOP;
RETURN;
END '
LANGUAGE 'plpgsql';
What I would like to do is pass in the column name that is being queried
against (cust_email) so it can be dynamic. I tried the following but it
always returns an empty set.

CREATE OR REPLACE FUNCTION lookup_customer(varchar,varchar) RETURNS SETOF
customer_rec AS
'
DECLARE
r RECORD;
in_string ALIAS FOR $1;
in_column ALIAS FOR $2;
BEGIN
FOR r IN SELECT
s_oid,mer_id,site_id,order_id,pymt_type,pymt_subty pe,comp_name,f_name1,l_nam
e1,f_name2,l_name2,address,city,state
,zipcode,phone,cust_email,country from customers where in_column ILIKE
in_string LOOP
RETURN NEXT r;
END LOOP;
RETURN;
END '
LANGUAGE 'plpgsql';
---------------------------(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 #1
1 1887
Yes that works, thanks for the tip.

Chris
----- Original Message -----
From: "Stephan Szabo" <ss****@megazone.bigpanda.com>
To: "Chris Ochs" <ch***@paymentonline.com>
Cc: <pg***********@postgresql.org>
Sent: Friday, June 04, 2004 3:06 PM
Subject: Re: [GENERAL] dynamic function question

On Fri, 4 Jun 2004, Chris Ochs wrote:
What I would like to do is pass in the column name that is being queried
against (cust_email) so it can be dynamic. I tried the following but it always returns an empty set.

CREATE OR REPLACE FUNCTION lookup_customer(varchar,varchar) RETURNS SETOF customer_rec AS
'
DECLARE
r RECORD;
in_string ALIAS FOR $1;
in_column ALIAS FOR $2;
BEGIN
FOR r IN SELECT
s_oid,mer_id,site_id,order_id,pymt_type,pymt_subty pe,comp_name,f_name1,l_nam e1,f_name2,l_name2,address,city,state
,zipcode,phone,cust_email,country from customers where in_column ILIKE
in_string LOOP


I think you're going to need to look at using FOR IN EXECUTE to do this
generating a query string, something like:

FOR r IN EXECUTE ''SELECT s_oid,mer_id,site_id,order_id,pymt_type,
pymt_subtype,comp_name,f_name1,l_name1,f_name2,l_n ame2,address,
city,state,zipcode,phone,cust_email,country from customers
where '' || in_column || '' ILIKE '' || in_string
LOOP

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

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

Nov 23 '05 #2

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

Similar topics

6
by: Vasileios Zografos | last post by:
Hello, I have a function that generates some values (e.g. vertices in 2d space) the number of which I dont know. So, it could generate 20 vertices, 100 vertices, or even 1 vertex. void...
5
by: Todd Huish | last post by:
I have noticed something disturbing when retrieving datasets over a relatively slow line (multiple T1). I am looking at about 25 seconds to retrieve 500 rows via a php-odbc link. This same select...
14
by: Ina Schmitz | last post by:
Hello, I would like to get the logical and physical reads for every sql statement executed. Thatfore, I used the command "db2 get snapshot for dynamic sql on <mydatabase>". There, I could see...
3
by: MikeY | last post by:
Hi Everyone, I am working in C#, windows forms.My question is this. All my button dynamic controls properties are present and accounted for except for the"FlatStyle" properties. I can't seem to...
8
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was...
5
by: swarsa | last post by:
Hi All, I realize this is not a Palm OS development forum, however, even though my question is about a Palm C program I'm writing, I believe the topics are relevant here. This is because I...
6
by: MikeY | last post by:
Hi Everyone, Does anyone know where I can get my hands on a sample with source code of a simple dynamic button control in C# Windows form. I am looking for a sample that uses a class library...
7
by: Jo | last post by:
Hi, How can i differentiate between static and dynamic allocated objects? For example: void SomeFunction1() { CObject *objectp = new CObject; CObject object;
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
0
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...
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.