Re: [HACKERS] Given a view relation OID, how to construct a Query?

2015-12-09 Thread Eric Ridge
On Wed, Dec 9, 2015 at 5:07 PM Tom Lane  wrote:

>
> FWIW, it's exposed in 9.4 and up.  But in older branches you could
> probably just copy it, it's not that big.
>

That's good to know, thanks.  I did copy it and it's almost 3x faster than
going through SPI.  Thanks again for the pointer.

eric


Re: [HACKERS] Given a view relation OID, how to construct a Query?

2015-12-09 Thread Tom Lane
Eric Ridge  writes:
> On Wed, Dec 9, 2015 at 4:04 PM Tom Lane  wrote:
>> Open the relation and use get_view_query(), perhaps.

> I figured there was something simple, but I couldn't find it.  Thanks!
> Sadly, it's static.

FWIW, it's exposed in 9.4 and up.  But in older branches you could
probably just copy it, it's not that big.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Given a view relation OID, how to construct a Query?

2015-12-09 Thread Eric Ridge
On Wed, Dec 9, 2015 at 4:04 PM Tom Lane  wrote:

> Eric Ridge  writes:
> > 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.
>
> Open the relation and use get_view_query(), perhaps.


I figured there was something simple, but I couldn't find it.  Thanks!
Sadly, it's static.

eric


Re: [HACKERS] Given a view relation OID, how to construct a Query?

2015-12-09 Thread Tom Lane
Eric Ridge  writes:
> 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.

Open the relation and use get_view_query(), perhaps.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] Given a view relation OID, how to construct a Query?

2015-12-09 Thread Eric Ridge
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