Re: column length? - Mailing list pgsql-novice

From Tom Lane
Subject Re: column length?
Date
Msg-id 16504.1003894388@sss.pgh.pa.us
Whole thread Raw
In response to column length?  ("Mark McArthey" <mcarthey@execpc.com>)
List pgsql-novice
"Mark McArthey" <mcarthey@execpc.com> writes:
> I am wondering how the column length is determined.  The attached output is
> for my test table.  Running '\d player' shows me that the columns are
> varchar(20), but the attlen is listed as -1.  Where does the value '20' come
> from?

attlen = -1 is a generic value indicating "variable length type".  All
columns of varchar type will have attlen = -1 (as will all columns of
any other variable-length datatype).  The gold is hidden in the
atttypmod column, which has a datatype-specific interpretation.
For varchar columns, atttypmod is interpreted as "max chars plus 4".
(The plus-4 is a historical wart.)  See
src/backend/utils/adt/format_type.c for info about the interpretation of
typmod for other datatypes.

            regards, tom lane

pgsql-novice by date:

Previous
From: "Josh Berkus"
Date:
Subject: Re: Performance question (PostgreSQL 7.1.3)
Next
From: "Luca Carrettin"
Date:
Subject: Problem running C function