pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Parse a statement, get parameter types and return types
3+ messages / 2 participants
[nested] [flat]

* Parse a statement, get parameter types and return types
@ 2005-07-18 13:03 Richard Jones <rich@annexia.org>
  2005-07-18 13:58 ` Re: Parse a statement, get parameter types and return types Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Richard Jones @ 2005-07-18 13:03 UTC (permalink / raw)
  To: pgsql-interfaces

Given a statement, eg:

  select foo from bar where col = $1

I'd really like to get the types deduced by the PostgreSQL parser for
the input variables ($1, etc.) and the result column(s).  eg. it might
be $1 :: int4 and foo :: text, or whatever.

It seems from reading about PQprepare that getting the input types
isn't yet possible, but might be in future:

http://www.postgresql.org/docs/current/static/libpq-exec.html#AEN23157

I have no idea where to start getting the result types.

Is this possible in some way?  Is the data perhaps hidden in one of
the pg_* system tables?

Note that I don't want to actually execute the statement, just parse
it.

Rich.

-- 
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Team Notepad - intranets and extranets for business - http://team-notepad.com



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Parse a statement, get parameter types and return types
  2005-07-18 13:03 Parse a statement, get parameter types and return types Richard Jones <rich@annexia.org>
@ 2005-07-18 13:58 ` Tom Lane <tgl@sss.pgh.pa.us>
  2005-07-18 17:01   ` Re: Parse a statement, get parameter types and return types Richard Jones <rich@annexia.org>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2005-07-18 13:58 UTC (permalink / raw)
  To: Richard Jones <rich@annexia.org>; +Cc: pgsql-interfaces

Richard Jones <rich@annexia.org> writes:
> Given a statement, eg:
>   select foo from bar where col = $1

> I'd really like to get the types deduced by the PostgreSQL parser for
> the input variables ($1, etc.) and the result column(s).

This is possible at the protocol level -- see Describe Statement.
I'm not sure which client libraries let you get at the results ...
libpq isn't one of them :-(

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Parse a statement, get parameter types and return types
  2005-07-18 13:03 Parse a statement, get parameter types and return types Richard Jones <rich@annexia.org>
  2005-07-18 13:58 ` Re: Parse a statement, get parameter types and return types Tom Lane <tgl@sss.pgh.pa.us>
@ 2005-07-18 17:01   ` Richard Jones <rich@annexia.org>
  0 siblings, 0 replies; 3+ messages in thread

From: Richard Jones @ 2005-07-18 17:01 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-interfaces

On Mon, Jul 18, 2005 at 09:58:44AM -0400, Tom Lane wrote:
> This is possible at the protocol level -- see Describe Statement.
> I'm not sure which client libraries let you get at the results ...
> libpq isn't one of them :-(

Thanks for answering my question so promptly!

I've made a small patch against 8.0.3 which adds this functionality to
libpq-fe.  However I am not very certain of how the asynchronous stuff
works in this library, so it will need careful checking.
Nevertheless, it Works For Me in the limited testing I have done
against a 7.4 server.

http://annexia.org/tmp/PQsendDescribeStatement.diff

Note the user is expected to free(3) the Oids (types) array returned
by PQgetDescription.

Rich.

-- 
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Team Notepad - intranets and extranets for business - http://team-notepad.com



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2005-07-18 17:01 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-07-18 13:03 Parse a statement, get parameter types and return types Richard Jones <rich@annexia.org>
2005-07-18 13:58 ` Tom Lane <tgl@sss.pgh.pa.us>
2005-07-18 17:01   ` Richard Jones <rich@annexia.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox