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. -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general