pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedIs there a way to describe precision and scale for columns in a s elect statement using libpq?
5+ messages / 3 participants
[nested] [flat]
* Is there a way to describe precision and scale for columns in a s elect statement using libpq?
@ 2004-06-03 17:39 Brijesh Shrivastav <Bshrivastav@esri.com>
2004-06-07 00:44 ` Re: Is there a way to describe precision and scale for columns in a s L J Bayuk <ljb220@mindspring.com>
0 siblings, 1 reply; 5+ messages in thread
From: Brijesh Shrivastav @ 2004-06-03 17:39 UTC (permalink / raw)
To: pgsql-interfaces
Hi! All,
I am a new postgres developer and as is the case with many of us I am
porting
an existing application to postgres database. One of the requirement for us
is to be able to determine the scale and precision for select columns so we
can
accordingly allordingly allocate memory or inform client applications.
I looked at libpq api and found following api to describe a select statement
PQfname()
PQftype()
PQfsize()
However, PQfsize() gives me the space alloced for this column in database
row. How
can I get precision and scale for numeric columns?
I have run into another problem. I execute PREPARE statement with pgexec to
prepare
the query before executing it multiple time with different parameter values.
It
seems I can't get the select column information untill I perform an
PQexecPrepared().
Is there any way around it?
Thanks in advance,
Brijesh Shrivastav
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Is there a way to describe precision and scale for columns in a s
2004-06-03 17:39 Is there a way to describe precision and scale for columns in a s elect statement using libpq? Brijesh Shrivastav <Bshrivastav@esri.com>
@ 2004-06-07 00:44 ` L J Bayuk <ljb220@mindspring.com>
2004-06-07 03:34 ` Re: Is there a way to describe precision and scale for columns in a s Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 5+ messages in thread
From: L J Bayuk @ 2004-06-07 00:44 UTC (permalink / raw)
To: Bshrivastav@esri.com; +Cc: pgsql-interfaces
Brijesh Shrivastav wrote:
>
> Hi! All,
>
> I am a new postgres developer and as is the case with many of us I am
> porting
> an existing application to postgres database. One of the requirement for us
> is to be able to determine the scale and precision for select columns so we
> can
> accordingly allordingly allocate memory or inform client applications.
>
> I looked at libpq api and found following api to describe a select statement
>
> PQfname()
> PQftype()
> PQfsize()
>
> However, PQfsize() gives me the space alloced for this column in database
> row. How
> can I get precision and scale for numeric columns?
It's a little tricky. Use PQfmod() on the column. Call the result F.
The precision is the high 16 bits, and the scale is the low 16 bits,
but with an offset of 4 first:
precision = ((F - 4) >> 16) & 0xffff;
scale = (F - 4) & 0xffff;
> I have run into another problem. I execute PREPARE statement with pgexec to
> prepare
> the query before executing it multiple time with different parameter values.
> It
> seems I can't get the select column information untill I perform an
> PQexecPrepared().
> Is there any way around it?
I don't think so. The protocol supports it ("Describe" message on a named
prepared statement, without Bind or Execute), and I assume the backend
would play along, but I don't think libpq has any way to let you do it
in the current release.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Is there a way to describe precision and scale for columns in a s
2004-06-03 17:39 Is there a way to describe precision and scale for columns in a s elect statement using libpq? Brijesh Shrivastav <Bshrivastav@esri.com>
2004-06-07 00:44 ` Re: Is there a way to describe precision and scale for columns in a s L J Bayuk <ljb220@mindspring.com>
@ 2004-06-07 03:34 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 5+ messages in thread
From: Tom Lane @ 2004-06-07 03:34 UTC (permalink / raw)
To: L J Bayuk <ljb220@mindspring.com>; +Cc: Bshrivastav@esri.com; pgsql-interfaces
L J Bayuk <ljb220@mindspring.com> writes:
> Brijesh Shrivastav wrote:
>> It seems I can't get the select column information untill I perform an
>> PQexecPrepared().
>> Is there any way around it?
> I don't think so. The protocol supports it ("Describe" message on a named
> prepared statement, without Bind or Execute), and I assume the backend
> would play along, but I don't think libpq has any way to let you do it
> in the current release.
libpq doesn't currently have any API to let you get at
Describe-Statement. This is obviously something to fix. There are
actually quite a few aspects of the v3 backend protocol that libpq
has no API for as yet. I would like to see someone think about prepared
statements and parameters in general, and put forward a coherent
proposed API for the whole mess. But short of that, we could accept
a solution for this particular issue ...
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Is there a way to describe precision and scale f
@ 2004-06-08 00:52 Brijesh Shrivastav <Bshrivastav@esri.com>
2004-06-09 00:08 ` Re: Is there a way to describe precision and scale L J Bayuk <ljb220@mindspring.com>
0 siblings, 1 reply; 5+ messages in thread
From: Brijesh Shrivastav @ 2004-06-08 00:52 UTC (permalink / raw)
To: 'L J Bayuk' <ljb220@mindspring.com>; +Cc: pgsql-interfaces
Thanks for the comments. They were very helpful.
However, I am still not sure about the second problem
i.e. of describing the prepared statement. Does some
other api exposes it? Can I use some sql command to get
around it (I couldn't find any)? any other ideas?
Brijesh Shrivastav
-----Original Message-----
From: L J Bayuk [mailto:ljb220@mindspring.com]
Sent: Sunday, June 06, 2004 5:44 PM
To: Bshrivastav@esri.com
Cc: pgsql-interfaces@postgresql.org
Subject: Re: [INTERFACES] Is there a way to describe precision and scale
for columns in a s
Brijesh Shrivastav wrote:
>
> Hi! All,
>
> I am a new postgres developer and as is the case with many of us I am
> porting
> an existing application to postgres database. One of the requirement for
us
> is to be able to determine the scale and precision for select columns so
we
> can
> accordingly allordingly allocate memory or inform client applications.
>
> I looked at libpq api and found following api to describe a select
statement
>
> PQfname()
> PQftype()
> PQfsize()
>
> However, PQfsize() gives me the space alloced for this column in database
> row. How
> can I get precision and scale for numeric columns?
It's a little tricky. Use PQfmod() on the column. Call the result F.
The precision is the high 16 bits, and the scale is the low 16 bits,
but with an offset of 4 first:
precision = ((F - 4) >> 16) & 0xffff;
scale = (F - 4) & 0xffff;
> I have run into another problem. I execute PREPARE statement with pgexec
to
> prepare
> the query before executing it multiple time with different parameter
values.
> It
> seems I can't get the select column information untill I perform an
> PQexecPrepared().
> Is there any way around it?
I don't think so. The protocol supports it ("Describe" message on a named
prepared statement, without Bind or Execute), and I assume the backend
would play along, but I don't think libpq has any way to let you do it
in the current release.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Is there a way to describe precision and scale
2004-06-08 00:52 Re: Is there a way to describe precision and scale f Brijesh Shrivastav <Bshrivastav@esri.com>
@ 2004-06-09 00:08 ` L J Bayuk <ljb220@mindspring.com>
0 siblings, 0 replies; 5+ messages in thread
From: L J Bayuk @ 2004-06-09 00:08 UTC (permalink / raw)
To: Bshrivastav@esri.com; +Cc: pgsql-interfaces
Brijesh Shrivastav wrote:
>
> Thanks for the comments. They were very helpful.
>
> However, I am still not sure about the second problem
> i.e. of describing the prepared statement. Does some
> other api exposes it? Can I use some sql command to get
> around it (I couldn't find any)? any other ideas?
Since libpq doesn't expose it, no API based on libpq will let you at it.
There are a few non-libpq interfaces, but I doubt any have this advanced
feature. My pgin.tcl doesn't.
If your prepared query has a parameter which you can use to efficiently
select 0 (or a small number of rows), you might be able to use that as a
'dummy' query just to get column information. This is similar to the trick
of using "SELECT ... LIMIT 0" to get an empty result set just so you can
look at the column info.
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2004-06-09 00:08 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-06-03 17:39 Is there a way to describe precision and scale for columns in a s elect statement using libpq? Brijesh Shrivastav <Bshrivastav@esri.com>
2004-06-07 00:44 ` Re: Is there a way to describe precision and scale for columns in a s L J Bayuk <ljb220@mindspring.com>
2004-06-07 03:34 ` Re: Is there a way to describe precision and scale for columns in a s Tom Lane <tgl@sss.pgh.pa.us>
2004-06-08 00:52 Re: Is there a way to describe precision and scale f Brijesh Shrivastav <Bshrivastav@esri.com>
2004-06-09 00:08 ` Re: Is there a way to describe precision and scale L J Bayuk <ljb220@mindspring.com>
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