pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Bartek Teodorczyk <barteo@it.pl>
Cc: pgsql-interfaces@postgreSQL.org
Subject: Re: [INTERFACES] Getting field length in libpq
Date: Tue, 09 Mar 1999 10:08:57 -0500
Message-ID: <11997.920992137@sss.pgh.pa.us> (raw)
In-Reply-To: <36E533E9.B72B4C64@it.pl>

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



view thread (2+ messages)

Message-ID: <11997.920992137@sss.pgh.pa.us>
Permalink:  ../11997.920992137@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/11997.920992137@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: tgl@sss.pgh.pa.us, barteo@it.pl
  Subject: Re: [INTERFACES] Getting field length in libpq
  In-Reply-To: <11997.920992137@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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