Re: Size of varchar in an array

From: Dmitriy Igrishin <dmitigr(at)gmail(dot)com>
To: RW Shore <rws228(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Size of varchar in an array
Date: 2011-02-12 13:27:18
Message-ID: AANLkTikgHt0S8BjE7Gi0GVduh5m2zjeiB4UsMaYHsS0p@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hey,

2011/2/8 RW Shore <rws228(at)gmail(dot)com>

> I'm using the following type definition:
> create type typedef.BASIC_PEDIGREE as (
> DATE_ADDED TIMESTAMP,
> DESCRIPTION VARCHAR(128) [10]
> )\c
>
> I understand that PostgreSQL doesn't enforce the array length [10].
> However, I'd like to write an application that can retrieve this length AND
> the size of the varchar that makes up the array. I can't find these values
> anyplace in the various system catalogs or views. Does PostgreSQL keep this
> information someplace and if so where? If there's no way to retrieve (say)
> the max size of the varchar, does this mean that PostgreSQL does not enforce
> the max size of this field as well as not enforcing the array bounds?
>
I am not sure that Postgres keeps array size limits since, according to
http://www.postgresql.org/docs/9.0/static/arrays.html#ARRAYS-DECLARATION
"... current implementation ignores any supplied array size limits ..."
But it is possible to get maximum length of varchar:

SELECT atttypmod - 4 FROM pg_attribute
WHERE attrelid = 'typedef.BASIC_PEDIGREE'::regclass
AND attname = 'DESCRIPTION';

Please note that 4 is an integer which represents length.

--
// Dmitriy.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dmitriy Igrishin 2011-02-12 13:40:51 Re: SELECT INTO array[i] with PL/pgSQL
Previous Message Alban Hertroys 2011-02-12 12:16:27 Re: Multithreaded query onto 4 postgresql instances