dbTalk Databases Forums  

Passing TEXT variable to a function

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Passing TEXT variable to a function in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Tom Lane
 
Posts: n/a

Default Re: Passing TEXT variable to a function - 08-24-2004 , 04:23 PM






Betsy Barker <betsy.barker (AT) supportservicesinc (DOT) com> writes:
Quote:
Here is the call:

FOR getpercentiles IN EXECUTE ''SELECT * FROM get_facility_percentiles(''||wagerateid_list||'')' ' LOOP
-- RAISE NOTICE ''DONE CALLING FUNCTION '';
END LOOP;
You want something like

FOR getpercentiles IN EXECUTE ''SELECT * FROM get_facility_percentiles(''||quote_literal(wagerat eid_list)||'')'' LOOP


regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html



Reply With Quote
  #2  
Old   
Josh Berkus
 
Posts: n/a

Default Re: Passing TEXT variable to a function - 08-24-2004 , 04:28 PM






Betsy,

Quote:
The variable is defined as TEXT, and I'm trying to pass it to a function
that is setup to accept a TEXT parameter. Here is the call:
First off, let me say that you may be better off using a different strategy
for this. But I don't know much about your application, so you may not.

Quote:
FOR getpercentiles IN EXECUTE ''SELECT * FROM
get_facility_percentiles(''||wagerateid_list||'')' ' LOOP -- RAISE
NOTICE ''DONE CALLING FUNCTION '';
Aha, syntax error, you forgot the nested quotes:

FOR getpercentiles IN EXECUTE ''SELECT * FROM get_facility_percentiles(''''''
Quote:
| wagerateid_list || '''''')'' LOOP
FWIW, version 8.0 will have a feature to do away with the nested-quote-mania.

--
Josh Berkus
Aglio Database Solutions
San Francisco

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org



Reply With Quote
  #3  
Old   
Tom Lane
 
Posts: n/a

Default Re: Passing TEXT variable to a function - 08-24-2004 , 04:33 PM



Josh Berkus <josh (AT) agliodbs (DOT) com> writes:
Quote:
Aha, syntax error, you forgot the nested quotes:

FOR getpercentiles IN EXECUTE ''SELECT * FROM get_facility_percentiles(''''''
|| wagerateid_list || '''''')'' LOOP
She really wants quote_literal(), instead, so that the function doesn't
break if someone passes a value that contains quotes ...

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org



Reply With Quote
  #4  
Old   
Betsy Barker
 
Posts: n/a

Default Passing TEXT variable to a function - 08-24-2004 , 05:08 PM



Hello.
I have a function that creates a long TEXT string that looks like this:

30686,30687,30683,30689,30703,30677,30678,30707,30 701,30680,30694,30697,30692,30700,30699,30709,3069 8,30713,30684,30691,30706,30704,30688,30710,30685, 30708,30696,30695,30679,30681,30690,30702,30712,30 693,30711,30682,30705,30726,30728,30729,31885,3188 6,31887,30567,30568,30569,30570,30571,30572,30573, 30574,30575,30576,30577,30578,30579,30580,30581,30 582,30583,30584,30585,30586,30587,30588,30589,3059 0,30591,30592,30593,30594,30595,30596,30597,30598, 30599,30600,30601,30896,30903,30943,30945,30524,30 893,30894,30895,30897,30898,30899,30900,30901,3090 2,30904,30905,30906,30907,30908,30909,30910,30911, 30912,30913,30914,30915,30916,30917,30918,30919,30 920,30921,30922,30923,30924,30925,30926,30927,3092 8,30929,30930,30931,30932,30933,30934,30935,30936, 30937,30938,30939,30940,30941,30942,30944,30946,30 947,30948,30949,30950,30951,30952,30953

The variable is defined as TEXT, and I'm trying to pass it to a function that is setup to accept a TEXT parameter.
Here is the call:

FOR getpercentiles IN EXECUTE ''SELECT * FROM get_facility_percentiles(''||wagerateid_list||'')' ' LOOP
-- RAISE NOTICE ''DONE CALLING FUNCTION '';
END LOOP;

Here is the function declaration:
CREATE OR REPLACE FUNCTION get_facility_percentiles(TEXT) RETURNS public."percentiles" AS '

The problem is that I get this error:

WARNING: Error occurred while executing PL/pgSQL function calc_sum_facilities
WARNING: line 189 at for over execute statement
ERROR: Cannot pass more than 32 arguments to a function

So, it thinks I'm passing separate parameters.

I'm not sure what to do about this. If I have to put double quotes around it, I will need to strip them on the other side because the called function is using the TEXT string in a query like this:

select * from table where id in (TEXT);

Any help would be greatly appreciated!
Thank you in advance,

Best Regards,

--
Betsy Barker
IT Manager
Support Services, Inc
(720)489-1630 X 38

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly


Reply With Quote
  #5  
Old   
Betsy Barker
 
Posts: n/a

Default Re: Passing TEXT variable to a function - 08-24-2004 , 06:28 PM



quote_literal() worked. Thank you both!

On Tue, 24 Aug 2004 17:33:08 -0400
Tom Lane <tgl (AT) sss (DOT) pgh.pa.us> wrote:

Quote:
Josh Berkus <josh (AT) agliodbs (DOT) com> writes:
Aha, syntax error, you forgot the nested quotes:

FOR getpercentiles IN EXECUTE ''SELECT * FROM get_facility_percentiles(''''''
|| wagerateid_list || '''''')'' LOOP

She really wants quote_literal(), instead, so that the function doesn't
break if someone passes a value that contains quotes ...

regards, tom lane


--
Betsy Barker
IT Manager
Support Services, Inc
(720)489-1630 X 38

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.