How to count elements in an array?

From: Grant <grant(at)conprojan(dot)com(dot)au>
To: pgsql-sql(at)postgresql(dot)org
Subject: How to count elements in an array?
Date: 2001-03-05 22:49:52
Message-ID: Pine.LNX.4.21.0103060849160.2044-100000@webster.conprojan.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

How can I obtain a count (number) of elements in a text array? Thanks.

test=# \d array
Table "array"
Attribute | Type | Modifier
--------------+---------+------------------------------------------------
id | integer | not null default nextval('array_id_seq'::text)
to_group_ids | text[] |
Index: array_pkey

test=#

--- EXAMPLE SELECT ---

test=# select to_group_ids[1] from array where id=1;
to_group_ids
--------------
1
(1 row)

test=#

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Fork 2001-03-05 22:53:38 Re: Optimizing Query
Previous Message Mathijs Brands 2001-03-05 22:14:13 Re: How do I use text script containing SQL?