Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VfB9C-00071S-CO for pgsql-interfaces@arkaria.postgresql.org; Sat, 09 Nov 2013 16:12:30 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VfB9B-00034Y-Ir for pgsql-interfaces@arkaria.postgresql.org; Sat, 09 Nov 2013 16:12:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VfB99-00034P-NZ for pgsql-interfaces@postgresql.org; Sat, 09 Nov 2013 16:12:27 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VfB92-0004Sw-Kr for pgsql-interfaces@postgresql.org; Sat, 09 Nov 2013 16:12: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 rA9GCH3C031977; Sat, 9 Nov 2013 11:12:17 -0500 From: Tom Lane To: Mark Crosland cc: pgsql-interfaces@postgresql.org Subject: Re: Traversing the catalog using heap_open, systable_beginscan, ... In-reply-to: References: Comments: In-reply-to Mark Crosland message dated "Fri, 08 Nov 2013 21:37:02 -0800" Date: Sat, 09 Nov 2013 11:12:17 -0500 Message-ID: <31976.1384013537@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-interfaces Precedence: bulk Sender: pgsql-interfaces-owner@postgresql.org Mark Crosland writes: > Hello, > I am writing a foreign data wrapper and following the oracle example. Are > there docs that discuss heap_open, systable_beginscan and systable_getnext? > I currently just need to do simple stuff, like translate an Oid that is > received via a FDW callback into the text name of a table. I see all of the > catalog headers, pg_class.h, etc... but not seeing the pattern of which > args to pass into ScanKeyInit to traverse the catalog correctly. Well, you *can* look that sort of stuff up that way, but usually there's a better way; in particular, if at all possible you should consult the catalog caches instead. Look into src/backend/utils/cache/lsyscache.c for convenience routines that do this sort of thing. The particular need you cite above is addressed by get_rel_name(), and even if you don't see an exact fit, the routines provide good examples for fetching fields out of catalog entries. Also, once you've got a Relation pointer, much of what you might want to know about that table is available directly out of the relcache entry. regards, tom lane -- Sent via pgsql-interfaces mailing list (pgsql-interfaces@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-interfaces