Re: Dynamic queries in stored procedure

From: Scott Barney <scott(at)calculatedsteam(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: Dynamic queries in stored procedure
Date: 2013-07-05 14:50:47
Message-ID: 51D6DD47.6020606@calculatedsteam.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

I do this all the time; In fact, I've written a dynamic aggregate engine
that uses a sudo bind variable technique & dynamic joins with dependency
injection because the table names and query logic are not known at run
time - all in plpgsql.

sb
On 7/5/2013 9:26 AM, Andrew Dunstan wrote:
>
> On 07/05/2013 09:57 AM, Greg Jaskiewicz wrote:
>> Hey,
>>
>> We have a search method that depending on search params will join 3-5
>> tables, craft the joins and where section. Only problem is, this is
>> done in rather horrible java code. So using pgtap for tests is not
>> feasible.
>> I want to move the database complexity back to database, almost
>> writing the query construction in the plpgsql or python as stores
>> procedure, any suggestions ?
>>
>> Unfortunately PostgreSQL won't eliminate unnecessary joins from a
>> view, so I can't just create one view and simple code adding where's,
>> order by, etc.
>>
>> No, I don't want to use orm.
>>
>
> It's a matter of taste. Pretty much every PL has facilities for
> constructing and running dynamic sql. PLPgsql ,PLPerl, PLV8 ...
>
> cheers
>
> andrew
>
>
>
>

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Radu-Stefan Zugravu 2013-07-07 07:28:11 How to properly index hstore tags column to faster search for keys
Previous Message Misa Simic 2013-07-05 14:46:31 Re: Dynamic queries in stored procedure