Re: Get Columns from Plan

From: Isaac Morland <isaac(dot)morland(at)gmail(dot)com>
To: Ed Behn <ed(at)behn(dot)us>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Get Columns from Plan
Date: 2018-07-23 02:20:08
Message-ID: CAMsGm5ef+rmBU9Zm9jNMwP5_bugUMpBz6m0tgEALRSi1d37oiQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 22 July 2018 at 21:56, Ed Behn <ed(at)behn(dot)us> wrote:

> I'm tinkering with the idea of creating a Procedural Language plugin for
> Haskell. As such I'm reading up on the SPI and prepared statements. The
> idea is that a statement will be prepared at compile time and executed at
> run-time. Therefore, I want to be able to determine the columns (names and
> types) that are returned by a plan without executing it. It seems like this
> should be a straight-forward task, but there doesn't seem to be a mechanism
> to do this.
>
> Is there a way to get the columns for a plan at compile time? If not, why?
>

It looks to me like PQdescribePrepared() gives you most of what you want:

https://www.postgresql.org/docs/current/static/libpq-exec.html

You can get the types of the columns. However, it's not immediately obvious
to me how to get the column names. For query results there is PQfname() to
get the column names, but I believe that requires running the query. I
suppose you could add "LIMIT 0" to the end of the query and run it, but
that doesn't feel ideal.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Chenxi Li 2018-07-23 03:08:04 code of partition split
Previous Message Ed Behn 2018-07-23 01:56:18 Get Columns from Plan