Re: [HACKERS] Re: [INTERFACES] retrieving varchar size - Mailing list pgsql-hackers

From Byron Nikolaidis
Subject Re: [HACKERS] Re: [INTERFACES] retrieving varchar size
Date
Msg-id 353FDE5F.30748CC1@insightdist.com
Whole thread Raw
In response to Re: [HACKERS] Re: [INTERFACES] retrieving varchar size  (Bruce Momjian <maillist@candle.pha.pa.us>)
Responses Re: [HACKERS] Re: [INTERFACES] retrieving varchar size
List pgsql-hackers

Bruce Momjian wrote:

> Can't you do:
>
>         select atttypmod from pg_attribute
>         where attrelid = 10003 and attname = 'col1';
>
> That will give the length + 4 bytes.
>

The problem with that theory is this.  If the frontend application just
executes some random query, such as "select * from table", you really do not
know anything about what is coming back. You must rely on the little bit of
information the protocol gives you.  In the case of Postgres, it gives you
the fieldname, datatype, and size for each column in the result.
Unfortunately, for varchar and char(n), the size reports -1.  This is not
very helpful for describing the result set.

Your above example works fine (in fact we use that already) when you know the
table and column name, as in metadata functions such as SQLColumns() in the
ODBC driver.

Byron


pgsql-hackers by date:

Previous
From: The Hermit Hacker
Date:
Subject: Re: [HACKERS] AIX needs a new port maintainer.
Next
From: Brett McCormick
Date:
Subject: Re: [HACKERS] Re: [QUESTIONS] Anything like strftime() for PostgreSQL?