Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fVKqT-000223-SJ for pgsql-general@arkaria.postgresql.org; Tue, 19 Jun 2018 17:55:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fVIDD-00039s-Pt for pgsql-general@arkaria.postgresql.org; Tue, 19 Jun 2018 15:06:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fVIDD-00039i-IC for pgsql-general@lists.postgresql.org; Tue, 19 Jun 2018 15:06:27 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fVID9-000519-Pd for pgsql-general@postgresql.org; Tue, 19 Jun 2018 15:06:27 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w5JF6JYL020577; Tue, 19 Jun 2018 11:06:19 -0400 From: Tom Lane To: Aron Widforss cc: pgsql-general@postgresql.org Subject: Re: Find schema-qualified table name given unqualified name In-reply-to: <1529418016.355123.1413189224.75962718@webmail.messagingengine.com> References: <1529418016.355123.1413189224.75962718@webmail.messagingengine.com> Comments: In-reply-to Aron Widforss message dated "Tue, 19 Jun 2018 16:20:16 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <20575.1529420779.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 19 Jun 2018 11:06:19 -0400 Message-ID: <20576.1529420779@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Aron Widforss writes: > I'm interested in finding a (any) unique identifier for a table given an= unqualified name of the table. Is that feasible in SQL or a C function? Something like this might help you: select relnamespace::regnamespace from pg_class where oid =3D 'mytablename'::regclass; This will fail (not just return an empty set) if 'mytablename' isn't resolvable, so you might need some hackery to cope with that. Also, if you need it to work pre-9.5, you'll need to write an explicit join to pg_namespace instead of relying on regnamespace. regards, tom lane