Given a view relation OID, how to construct a Query?

From: Eric Ridge <eebbrr(at)gmail(dot)com>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Given a view relation OID, how to construct a Query?
Date: 2015-12-09 22:35:40
Message-ID: CANcm6wZs7=pzCbErBfSDt0JRUkEsqpRGwvh=ihGnoLdioK24Gg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2015-12-09 23:03:05 Re: Making tab-complete.c easier to maintain
Previous Message Peter Geoghegan 2015-12-09 22:23:11 Re: Re: Reusing abbreviated keys during second pass of ordered [set] aggregates