Tuesday, October 28. 2008Quick Guide to writing PLPGSQL Functions: Part 2Printer FriendlyRecommended Books: PostgreSQL: Up and Running
Trackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
Dear Sir,
I want to use syntx like below ... "("+ strValue + " -" + minNumber + "/"+ Maxnumber+"-"+minNumber+") * 100"; the above code is in C#.net. I am using npgsql.dll. Here my problem is i want write StoredProcedure which has to declare above syntax(strvalue is checkbox item) and maxnumber and minnumber i have to calculate in StoredProcedure and i have to send to above syntax . is it possible to do the above.if it is possible can you give sample code.. I am waiting for your great response. Advanced Thanks, Venkat.
Venkat,
Not quite sure what you are trying to do here. Are you trying to output the result of a formula or a string representation of a formula. When you say maxnum and min number are calculated in stored proc, how are you calculating it. Can you write that in C# and I'll try to help translate it to sql or plpgsql. Depending on what you are trying to do writing your stored proc (stored function) in sql instead of plpgsql may be more appropriate. hope that helps, Regina
Dear Regina,
Thanks for your great response,the below query i am using .when i run this query in pgsql query builder.I am getting good result.but i do not know how to write in procedures.I am new to postgresql. Please let me know.I am waiting for your great response. Select population ,(population-(Min(population)/Max(population)-Min(population)*100)) as Expression from metros_table group by population; Thanks, Venkat
Venkat,
I'm sorry I'm still not getting what you are trying to do. If you group by population, won't min and max population be the same so your query explodes. I assume you mean then that strValue field is dynamic but you are always getting min(population), max(population) ? Also are you trying to return a set of records or just one answer. If you want strValue (field population) to be dynamic, then I guess you do have to go with plpgsql rather than sql function.
How about this
CREATE OR REPLACE FUNCTION fnanswer(strValue float, minNum float, maxnum float) RETURNS float AS $$ SELECT ($1 - $2 / $3 - $2) * 100; $$ language 'sql'
Thanks for this - it may be basic but it was well timed and saved me hours. If you were across the room I'd buy you a pint ;-)
|
Entry's LinksQuicksearchCalendar
Categories
Blog Administration |