Search code examples
postgresqlselectlibpq

Get all the tables involved in a SELECT query in PostgreSQL using `libpq'


Is it possible to get the names or (Oid's) for all queried tables with libpq? If there exists a generic standard SQL way i would prefer it.


Solution

  • It's not standard, but the Postgres EXPLAIN command can give you (more than) what you want.

    http://www.postgresql.org/docs/9.3/static/sql-explain.html

    If you use the JSON output format, the table names are found in the "Relation Name" attributes of the "Plan" objects.