Skip site navigation (1) Skip section navigation (2)

Re: [INTERFACES] Getting field length in libpq

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bartek Teodorczyk <barteo(at)it(dot)pl>
Cc: pgsql-interfaces(at)postgreSQL(dot)org
Subject: Re: [INTERFACES] Getting field length in libpq
Date: 1999-03-09 15:08:57
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
Bartek Teodorczyk <barteo(at)it(dot)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

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

pgsql-interfaces by date

Next:From: Thomas G. LockhartDate: 1999-03-09 15:20:14
Subject: Re: [INTERFACES] the last row in a table
Previous:From: Thomas G. LockhartDate: 1999-03-09 15:08:05
Subject: Re: [INTERFACES] Bug in sortin routine?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group