agora inbox for pgsql-interfaces@postgresql.org  
help / color / mirror / Atom feed
Traversing the catalog using heap_open, systable_beginscan, ...
4+ messages / 2 participants
[nested] [flat]

* Traversing the catalog using heap_open, systable_beginscan, ...
@ 2013-11-09 05:37  Mark Crosland <mark.crosland@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Mark Crosland @ 2013-11-09 05:37 UTC (permalink / raw)
  To: pgsql-interfaces

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.

Hints greatly appreciated.
If there is a better list, please point me to it.

Thanks,
Mark

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Traversing the catalog using heap_open, systable_beginscan, ...
@ 2013-11-09 16:12  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Mark Crosland <mark.crosland@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Tom Lane @ 2013-11-09 16:12 UTC (permalink / raw)
  To: Mark Crosland <mark.crosland@gmail.com>; +Cc: pgsql-interfaces

Mark Crosland <mark.crosland@gmail.com> 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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Traversing the catalog using heap_open, systable_beginscan, ...
@ 2013-11-11 22:01  Mark Crosland <mark.crosland@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Mark Crosland @ 2013-11-11 22:01 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-interfaces

Thanks, that helps. I can get table and column info from the catalog now.

What is the recommended way (structs to access via one of the scan/modify
callbacks?) to retrieve the column, operation and value, "col", "=" and
"val" in this example. And is the same method used for both queries and
updates?
select * from table where col=val

A lot of the FDW examples seem to use table options, which isn't quite what
we need. We are going for more of a mapping between tables in different DBs.

Thanks,


On Sat, Nov 9, 2013 at 8:12 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Mark Crosland <mark.crosland@gmail.com> 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
>

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Traversing the catalog using heap_open, systable_beginscan, ...
@ 2013-11-12 02:03  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Mark Crosland <mark.crosland@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2013-11-12 02:03 UTC (permalink / raw)
  To: Mark Crosland <mark.crosland@gmail.com>; +Cc: pgsql-interfaces

Mark Crosland <mark.crosland@gmail.com> writes:
> Thanks, that helps. I can get table and column info from the catalog now.
> What is the recommended way (structs to access via one of the scan/modify
> callbacks?) to retrieve the column, operation and value, "col", "=" and
> "val" in this example. And is the same method used for both queries and
> updates?
> select * from table where col=val

contrib/postgres_fdw might be a useful example for you.  A lot of this
stuff isn't documented terribly well, you just have to look for some
example code that does what you want to do.

			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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2013-11-12 02:03 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-11-09 05:37 Traversing the catalog using heap_open, systable_beginscan, ... Mark Crosland <mark.crosland@gmail.com>
2013-11-09 16:12 ` Tom Lane <tgl@sss.pgh.pa.us>
2013-11-11 22:01   ` Mark Crosland <mark.crosland@gmail.com>
2013-11-12 02:03     ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox