pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Getting field length in libpq
2+ messages / 2 participants
[nested] [flat]

* Getting field length in libpq
@ 1999-03-09 14:44 Bartek Teodorczyk <barteo@it.pl>
  1999-03-09 15:08 ` Re: [INTERFACES] Getting field length in libpq Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: Bartek Teodorczyk @ 1999-03-09 14:44 UTC (permalink / raw)
  To: pgsql-interfaces

I have following problem:
I need to get the length of field after executing query. For INT4 fields
it is simple (call PQfsize and get 4) but when I have VARCHAR(30) field
PQfsize returns -1. I cannot call PQgetlength for example first tuple
because this tuple can have 10 chars and PQgetlength returns 10 but I
need 30. Have you any solutions?

BarTeo



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

* Re: [INTERFACES] Getting field length in libpq
  1999-03-09 14:44 Getting field length in libpq Bartek Teodorczyk <barteo@it.pl>
@ 1999-03-09 15:08 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 1999-03-09 15:08 UTC (permalink / raw)
  To: Bartek Teodorczyk <barteo@it.pl>; +Cc: pgsql-interfaces

Bartek Teodorczyk <barteo@it.pl> writes:
> I need to get the length of field after executing query. For INT4 fields
> it is simple (call PQfsize and get 4) but when I have VARCHAR(30) field
> PQfsize returns -1. I cannot call PQgetlength for example first tuple
> because this tuple can have 10 chars and PQgetlength returns 10 but I
> need 30. Have you any solutions?

I believe PQfmod will give you the number you want, for the specific
case of char and varchar fields.  The meaning of PQfmod is by definition
type-specific, so there's no guarantee that it will contain the maximum
field width for other data types.  For that matter, there's no guarantee
that a VARLENA data type even *has* an identifiable maximum width ---
the handiest example of one that does not is text.

If I were you I'd check PQftype before assuming that I knew what PQfmod
means.

BTW, keep in mind that PQfsize is the stored size of a datum, but unless
you are using binary cursors it has nothing to do with the length of the
ASCII representation of the value...

			regards, tom lane



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


end of thread, other threads:[~1999-03-09 15:08 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-03-09 14:44 Getting field length in libpq Bartek Teodorczyk <barteo@it.pl>
1999-03-09 15:08 ` 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