By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,967 Members | 1,740 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,967 IT Pros & Developers. It's quick & easy.

Building an aggregate function

P: 33
Ok. I have a bit of a dilemma here. First, please consider the following function:

Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE FUNCTION recent_lab(text, labs, treatments)  RETURNS float8 AS
  2. $BODY$select cast(substring(lab_result from '[[:space:]]*([[:digit:].-]*)') as float)
  3. from labs b 
  4. where $ = and b.test = $1 and result ~ '[[:digit:]]' and b.time < $3.time and b.time > $3.time - interval '2 day'
  5. order by b.time desc
  6. limit 1$BODY$
In a nutshell, this function returns the most recent lab result within 2 days for a given lab test. Now my problem is that this isn't accepted as an aggregate function, and I need it to be. I've looked at the documentation for custom aggregate functions and to put it bluntly, I'm baffled. Can anybody provide any insight in converting my function to an aggregate?
Jul 23 '07 #1
Share this Question
Share on Google+
1 Reply

P: 33
bump, bump, bump, bump, bump,
Jul 25 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.