pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
leaving out paramTypes parameter
2+ messages / 2 participants
[nested] [flat]

* leaving out paramTypes parameter
@ 2006-08-14 13:38 Andro <andromede@gmail.com>
  2006-08-14 15:23 ` Re: leaving out paramTypes parameter Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: Andro @ 2006-08-14 13:38 UTC (permalink / raw)
  To: pgsql-interfaces

Hi,

from the documentation, here's PQexecParams prototype

PGresult *PQexecParams(PGconn *conn,
                       const char *command,
                       int nParams,
                       const Oid *paramTypes,
                       const char * const *paramValues,
                       const int *paramLengths,
                       const int *paramFormats,
                       int resultFormat);

and PQprepare's

PGresult *PQprepare(PGconn *conn,
                    const char *stmtName,
                    const char *query,
                    int nParams,
                    const Oid *paramTypes);

they both require "paramTypes" parameter, but documentation says "If
paramTypes is NULL, or any particular element in the array is zero,
the server assigns a data type to the parameter symbol in the same way
it would do for an untyped literal string."

How reliable is that? Can we really leave out this parameter anytime?
What are known issues? Or should we try at all costs to specify
parameters type?

Thanks

Charles



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

* Re: leaving out paramTypes parameter
  2006-08-14 13:38 leaving out paramTypes parameter Andro <andromede@gmail.com>
@ 2006-08-14 15:23 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2006-08-14 15:23 UTC (permalink / raw)
  To: Andro <andromede@gmail.com>; +Cc: pgsql-interfaces

Andro <andromede@gmail.com> writes:
> they both require "paramTypes" parameter, but documentation says "If
> paramTypes is NULL, or any particular element in the array is zero,
> the server assigns a data type to the parameter symbol in the same way
> it would do for an untyped literal string."

> How reliable is that? Can we really leave out this parameter anytime?

Like it says, you get the same results you would get from writing a
literal string 'foo' where the parameter symbol is.  If you like,
you can force the type decision with a cast in the query text, eg

	"SELECT ... WHERE x = $1::int8 ... "

In some ways this is better than using paramTypes because you don't
have to mess with numeric OIDs for data types.

			regards, tom lane



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


end of thread, other threads:[~2006-08-14 15:23 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-08-14 13:38 leaving out paramTypes parameter Andro <andromede@gmail.com>
2006-08-14 15:23 ` Tom Lane <tgl@sss.pgh.pa.us>

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