pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Get max value from an comma separated string
3+ messages / 3 participants
[nested] [flat]

* Get max value from an comma separated string
@ 2006-05-29 11:22 Mauro Bertoli <bertolima@yahoo.it>
  2006-06-05 02:12 ` Re: Get max value from an comma separated string Bruno Wolff III <bruno@wolff.to>
  2006-06-05 14:49 ` Re: Get max value from an comma separated string Bricklen Anderson <banderson@presinet.com>
  0 siblings, 2 replies; 3+ messages in thread

From: Mauro Bertoli @ 2006-05-29 11:22 UTC (permalink / raw)
  To: pgsql-sql

Hi, I've a field that contain values-comma-separated
like
A) 1;2;3;;5  -- ;2;;4;5
but also
B) 12;34;18
how I can get the max value?
For A I tried:
SELECT max(array_upper(string_to_array(answer,';'),1))
FROM values;
and work fine, but for B case I don't find a solution
like
SELECT max(string_to_array(answer,';')) FROM values;

Any ideas?
Thanks for any hint

Chiacchiera con i tuoi amici in tempo reale! 
 http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Get max value from an comma separated string
  2006-05-29 11:22 Get max value from an comma separated string Mauro Bertoli <bertolima@yahoo.it>
@ 2006-06-05 02:12 ` Bruno Wolff III <bruno@wolff.to>
  1 sibling, 0 replies; 3+ messages in thread

From: Bruno Wolff III @ 2006-06-05 02:12 UTC (permalink / raw)
  To: Mauro Bertoli <bertolima@yahoo.it>; +Cc: pgsql-sql

On Mon, May 29, 2006 at 13:22:38 +0200,
  Mauro Bertoli <bertolima@yahoo.it> wrote:
> Hi, I've a field that contain values-comma-separated
> like
> A) 1;2;3;;5  -- ;2;;4;5
> but also
> B) 12;34;18
> how I can get the max value?
> For A I tried:
> SELECT max(array_upper(string_to_array(answer,';'),1))
> FROM values;
> and work fine, but for B case I don't find a solution
> like
> SELECT max(string_to_array(answer,';')) FROM values;
> 
> Any ideas?
> Thanks for any hint

Don't store the data like that in the database if possible.



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Get max value from an comma separated string
  2006-05-29 11:22 Get max value from an comma separated string Mauro Bertoli <bertolima@yahoo.it>
@ 2006-06-05 14:49 ` Bricklen Anderson <banderson@presinet.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Bricklen Anderson @ 2006-06-05 14:49 UTC (permalink / raw)
  To: Mauro Bertoli <bertolima@yahoo.it>; +Cc: pgsql-sql

Mauro Bertoli wrote:
> Hi, I've a field that contain values-comma-separated
> like
> A) 1;2;3;;5  -- ;2;;4;5
> but also
> B) 12;34;18
> how I can get the max value?
> For A I tried:
> SELECT max(array_upper(string_to_array(answer,';'),1))
> FROM values;
> and work fine, but for B case I don't find a solution
> like
> SELECT max(string_to_array(answer,';')) FROM values;
> 
> Any ideas?
> Thanks for any hint
> 
You could try rearranging the values into rows, like so:

CREATE OR REPLACE FUNCTION text2rows (TEXT,TEXT) RETURNS SETOF TEXT AS $$
SELECT (string_to_array($1, $2))[x.i]
FROM generate_series(1,array_upper(string_to_array($1,$2),1)) AS x(i);
$$ language sql strict;

select max(val)
from (SELECT text2rows(answer,';') as val FROM answer) as t;



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2006-06-05 14:49 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-05-29 11:22 Get max value from an comma separated string Mauro Bertoli <bertolima@yahoo.it>
2006-06-05 02:12 ` Bruno Wolff III <bruno@wolff.to>
2006-06-05 14:49 ` Bricklen Anderson <banderson@presinet.com>

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