Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Uv7Lc-0003Bb-3D for pgsql-performance@arkaria.postgresql.org; Fri, 05 Jul 2013 14:50:56 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Uv7Lb-0006uu-Ja for pgsql-performance@arkaria.postgresql.org; Fri, 05 Jul 2013 14:50:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Uv7La-0006uo-Pf for pgsql-performance@postgresql.org; Fri, 05 Jul 2013 14:50:54 +0000 Received: from mail2.runhosting.com ([82.197.130.210]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Uv7LU-0006Y4-7y for pgsql-performance@postgresql.org; Fri, 05 Jul 2013 14:50:54 +0000 Received: from mail2.runhosting.com (out2.defender.mail [82.197.130.206]) by mail2.runhosting.com (Postfix) with ESMTP id DA174899B876 for ; Fri, 5 Jul 2013 14:50:46 +0000 (UTC) Received: from [10.1.10.16] (unknown [38.106.228.154]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail2.runhosting.com (Postfix) with ESMTPSA id 9573C899B85E for ; Fri, 5 Jul 2013 14:50:46 +0000 (UTC) Message-ID: <51D6DD47.6020606@calculatedsteam.com> Date: Fri, 05 Jul 2013 09:50:47 -0500 From: Scott Barney User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Dynamic queries in stored procedure References: <96F5E9DF-8F6E-4EF6-B0AE-43B585B11F94@gmail.com> <51D6D7A2.3030206@dunslane.net> In-Reply-To: <51D6D7A2.3030206@dunslane.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV using ClamSMTP (out2.defender.mail(82.197.130.206), client: 82.197.130.204) 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 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 > > > > -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance