pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: A. Kretschmer <andreas.kretschmer@schollglas.com>
To: pgsql-sql@postgresql.org
Subject: Re: how to generate a list of distinct scalar values from a column which type is array
Date: Thu, 22 Feb 2007 14:34:33 +0100
Message-ID: <20070222133433.GF15488@a-kretschmer.de> (raw)
In-Reply-To: <20070222132536.GE15488@a-kretschmer.de>
References: <2cfc7c940702211021u1ba47031l25112a69cfb18338@mail.gmail.com>
	<20070222132536.GE15488@a-kretschmer.de>

am  Thu, dem 22.02.2007, um 14:25:36 +0100 mailte A. Kretschmer folgendes:
> test=*# select * from a;
>       c
> -------------
>  {aaa,bb,c}
>  {dddd,eeee}
>  {aaa,eeee}
> (3 rows)
> 
> 
> test=*# select distinct c[s] from a,  generate_series(1,3)s where c[s] is not null;
>   c
> ------
>  aaa
>  bb
>  c
>  dddd
>  eeee
> (5 rows)
> 
> 
> You need to know the greatest upper dimension of the array, in this case
> 3, for the generate_series - function.

select distinct c[s] from a,  generate_series(1,(select max(array_upper(c,1)) from a))s where c[s] is not null;

;-)


Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net



view thread (6+ messages)  latest in thread

Message-ID: <20070222133433.GF15488@a-kretschmer.de>
Permalink:  ../20070222133433.GF15488@a-kretschmer.de/
Also on:    postgresql.org/message-id/20070222133433.GF15488@a-kretschmer.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: andreas.kretschmer@schollglas.com
  Subject: Re: how to generate a list of distinct scalar values from a column which type is array
  In-Reply-To: <20070222133433.GF15488@a-kretschmer.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox