Given a view relation OID, how to construct a Query? - Mailing list pgsql-hackers

From Eric Ridge
Subject Given a view relation OID, how to construct a Query?
Date
Msg-id CANcm6wZs7=pzCbErBfSDt0JRUkEsqpRGwvh=ihGnoLdioK24Gg@mail.gmail.com
Whole thread Raw
Responses Re: Given a view relation OID, how to construct a Query?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
I'm doing some extension development (in C) and have a situation where I need to examine the target list of a view, but all I have is the view's oid.

An approach that works is (pseudocode):
   SPI_connect();
   "SELECT ev_action FROM pg_catalog.pg_rewrite WHERE rulename = '_RETURN' and ev_class=?oid";
   Query *query = linitial(stringToNode(ev_action));
   ...
   SPI_finish();

I backed into this by tracing through pg_getviewdef().  Is there a more direct way to do this without going through SPI?

I also looked at using postgres.c#pg_analyze_and_rewrite() against a query like "SELECT * FROM viewname" but the target list of the actual query wasn't what I was expecting (individual entry tags don't match those of the SPI approach above).

Thanks for your time!

eric

pgsql-hackers by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: Re: Reusing abbreviated keys during second pass of ordered [set] aggregates
Next
From: Michael Paquier
Date:
Subject: Re: Making tab-complete.c easier to maintain