Re: column length?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Mark McArthey" <mcarthey(at)execpc(dot)com>
Cc: "PgSQL Novice" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: column length?
Date: 2001-10-24 03:33:08
Message-ID: 16504.1003894388@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

"Mark McArthey" <mcarthey(at)execpc(dot)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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Daniel Bautista 2001-10-24 13:29:24 current and beta versions
Previous Message Jochem van Dieten 2001-10-23 23:08:57 Re: Performance question (PostgreSQL 7.1.3)