Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 1F1C51337999 for ; Fri, 31 Dec 2010 11:04:31 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 90014-08 for ; Fri, 31 Dec 2010 15:04:23 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mail.postgresql.org (Postfix) with ESMTP id 6E401133798E for ; Fri, 31 Dec 2010 11:04:23 -0400 (AST) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1PYgWk-00035s-In for pgsql-jdbc@postgresql.org; Fri, 31 Dec 2010 16:04:22 +0100 Received: from ppp-188-174-74-32.dynamic.mnet-online.de ([188.174.74.32]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 31 Dec 2010 16:04:22 +0100 Received: from spam_eater by ppp-188-174-74-32.dynamic.mnet-online.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 31 Dec 2010 16:04:22 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Thomas Kellerer Subject: Re: java.sql.DatabaseMetaData.getProcedures and overloaded functions Date: Fri, 31 Dec 2010 16:04:20 +0100 Lines: 53 Message-ID: References: <1293738434.11427.34.camel@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: ppp-188-174-74-32.dynamic.mnet-online.de User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.5.666 In-Reply-To: <1293738434.11427.34.camel@localhost> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, T_RP_MATCHES_RCVD=-0.01, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201012/93 X-Sequence-Number: 21331 Thor Michael Støre wrote on 30.12.2010 20:47: > Is my understanding correct in that JDBC doesn't actually provide a > proper way of inspecting overloaded stored procedures, and so to get > that information reliably you should query the PostgreSQL system > catalogs? At least when I try to use the java.sql.DatabaseMetaData > getProcedures and getProcedureColumns methods on overloaded procedures I > see them repeated without any explicit distinction between them, except > of course that getProcedureColumns gives different datatypes for each > procedure. > I had to deal with this as well, and I finally implemented my own Postgres specific versions of getProcedures() and getProcedureColumns() in order to be able to support overloaded functions in my SQL Workbench. What I essentially did, was to retrieve the procedures using my own SQL Statement that would also return all argument types for that function. This argument list name can then be use to retrieve the corresponding parameters for that specific version. So getting the procedures is something like this: SELECT NULL AS PROCEDURE_CAT, n.nspname AS PROCEDURE_SCHEM, p.proname AS PROCEDURE_NAME, d.description AS REMARKS, array_to_string(p.proargtypes, ';') as PG_ARGUMENTS, case when p.proisagg then 'aggregate' else 'function' end as proc_type FROM pg_catalog.pg_namespace n, pg_catalog.pg_proc p LEFT JOIN pg_catalog.pg_description d ON (p.oid=d.objoid) LEFT JOIN pg_catalog.pg_class c ON (d.classoid=c.oid AND c.relname='pg_proc') LEFT JOIN pg_catalog.pg_namespace pn ON (c.relnamespace=pn.oid AND pn.nspname='pg_catalog') WHERE p.pronamespace=n.oid The PG_ARGUMENTS is the "magical" thing here. The value of that column can (more or less) be used later when retrieving the columns: SELECT format_type(p.prorettype, NULL) as formatted_type, t.typname as pg_type, coalesce(array_to_string(proallargtypes, ';'), array_to_string(proargtypes, ';')) as argtypes, array_to_string(p.proargnames, ';') as argnames, array_to_string(p.proargmodes, ';') as modes, t.typtype FROM pg_catalog.pg_proc p JOIN pg_catalog.pg_namespace n ON p.pronamespace = n.oid JOIN pg_catalog.pg_type t ON p.prorettype = t.oid WHERE n.nspname = 'public' AND p.proargtypes = cast('23 23' as oidvector); Feel free to have a look at the source code (http://www.sql-workbench.net). The class in question is workbench.db.postgres.PostgresProcedureReader. Hope this helps. Regards Thomas