Run aggregate function in Postgresql stored procedure -


i have question running built in aggregate functions within stored procedure on postgres.

i have query run function lot:

select      max(column_name) max_val,     min(column_name) min_val,     (column_name - min_val) / (max_val - min_val) my_value; 

i care final my_value parameter, , since need run method lot of columns i've been trying write stored procedure, can run select get_my_val(column_name); having trouble getting work correctly.

here's along lines of have right (note, wrong , not work):

create or replace function get_my_val(col varchar(32))     returns float     $body$     begin      return query execute             '(' || col || ' - min(' || col || ')) / (max(' || col || ') - min(' || col || '))';     end     $body$     language plpgsql; 

i think i'm using return query execute incorrectly. can give me push in right direction?


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo