Dynamic WHERE clause to call DB-function

From: Larry <l(dot)paige(at)live(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Dynamic WHERE clause to call DB-function
Date: 2012-01-25 18:25:52
Message-ID: 1327515952976-5430961.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I was wondering if something like this could be possible:

SELECT * FROM table1
WHERE a1 = ... AND a2 = ... AND b1 = ... AND b2 = ...

The first thing to note is that the WHERE clause is dynamic, as in it can
contain more parameters or lesser parameters.

But, what I want to try accomplish is that this query will return a type
B{b1,b2,...,}.

This type is pre-defined for each defined “table1”.

So the part where we have "b1 = ... AND b2 = ...”, this will apply like a
normal query-selection criteria over the returned results.

But what’s the main thing here is that the first part "a1 = ... AND a2 =
...” (i.e. anything this is not defined in B-type), I want to pass into a
function as a name/value pairs, for example func1(a1=...,a2=...), or maybe
even just a concatenation of String. It is also know that any defined func1
will always return a certain type, say B.

At the end of the day: I like the user to feel they're querying a table, but
in fact, for certain WHERE-clause params they are invoking a function, and
for others, it is applying a selection over the results returned.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Dynamic-WHERE-clause-to-call-DB-function-tp5430961p5430961.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

Browse pgsql-general by date

  From Date Subject
Next Message Misa Simic 2012-01-25 18:29:38 Re: Logging access to data in database table
Previous Message Greg Sabino Mullane 2012-01-25 18:17:44 Re: any plans to support more rounding methods in sql?