Skip site navigation (1) Skip section navigation (2)

Define a function that accepts query result as a parameter

From: Cheng <niechenghust(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Define a function that accepts query result as a parameter
Date: 2012-03-23 16:26:14
Message-ID: 4F6CA426.30205@gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
Hi all,

I have two tables A and B, I defined a function f() on A. The problem is 
to process the rows in A whose id has appeared in Table B. To save 
time,  I want to to run function f() on only records that appeared in B. 
I tried this:

define f(integer[]) as
$$
process records where id in $1
$$ language sql

then I tried to call the function using f(select array_agg(id) from B). 
It does not work.
Do you guys know how I can achieve this?

Thanks,
Cheng

Responses

pgsql-novice by date

Next:From: Rob RichardsonDate: 2012-03-23 18:06:29
Subject: Re: Define a function that accepts query result as a parameter
Previous:From: sreeaurovindh viswanathanDate: 2012-03-23 03:29:41
Subject: how to leverage index for order by

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group