Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Uv6yc-0001lP-Ow for pgsql-performance@arkaria.postgresql.org; Fri, 05 Jul 2013 14:27:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Uv6yc-0002hH-8b for pgsql-performance@arkaria.postgresql.org; Fri, 05 Jul 2013 14:27:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Uv6yb-0002hB-HA for pgsql-performance@postgresql.org; Fri, 05 Jul 2013 14:27:09 +0000 Received: from relay3-d.mail.gandi.net ([217.70.183.195]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Uv6yY-000657-Vv for pgsql-performance@postgresql.org; Fri, 05 Jul 2013 14:27:09 +0000 Received: from mfilter25-d.gandi.net (mfilter25-d.gandi.net [217.70.178.153]) by relay3-d.mail.gandi.net (Postfix) with ESMTP id 98099A80EB; Fri, 5 Jul 2013 16:26:46 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter25-d.gandi.net Received: from relay3-d.mail.gandi.net ([217.70.183.195]) by mfilter25-d.gandi.net (mfilter25-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id vjckXMmYdYnI; Fri, 5 Jul 2013 16:26:44 +0200 (CEST) X-Originating-IP: 98.27.58.255 Received: from [192.168.10.146] (cpe-098-027-058-255.nc.res.rr.com [98.27.58.255]) (Authenticated sender: adsend@dunslane.net) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 549FBA80BB; Fri, 5 Jul 2013 16:26:44 +0200 (CEST) Message-ID: <51D6D7A2.3030206@dunslane.net> Date: Fri, 05 Jul 2013 10:26:42 -0400 From: Andrew Dunstan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Greg Jaskiewicz CC: pgsql-performance@postgresql.org Subject: Re: Dynamic queries in stored procedure References: <96F5E9DF-8F6E-4EF6-B0AE-43B585B11F94@gmail.com> In-Reply-To: <96F5E9DF-8F6E-4EF6-B0AE-43B585B11F94@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org 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 -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance