dbTalk Databases Forums  

max of a varchar field

comp.databases.postgresql comp.databases.postgresql


Discuss max of a varchar field in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Dade
 
Posts: n/a

Default max of a varchar field - 10-11-2007 , 10:55 AM






Hello all,
i have a problem with the max value of a varchar field

id docno description
=================
1 2 test1
2 F10 test2


select max(docno::text) as "docno" from table

I woul like that it returns me F10, but it doesn't... how can i tell him to
give me the max value without consider the char part?

thanx all
Dade


Reply With Quote
  #2  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: max of a varchar field - 10-12-2007 , 02:58 AM






Dade <cucca77NOSPAM (AT) nospamgmail (DOT) com> wrote:
Quote:
i have a problem with the max value of a varchar field

id docno description
=================
1 2 test1
2 F10 test2


select max(docno::text) as "docno" from table

I woul like that it returns me F10, but it doesn't... how can i tell him to
give me the max value without consider the char part?
You'll have to strip out the letters and convert to integer before
computing the maximum. Something like this:

SELECT max(regexp_replace(docno, '[^[:digit:]]', '', 'g')::integer)
FROM "table"

Yours,
Laurenz Albe


Reply With Quote
  #3  
Old   
Dade
 
Posts: n/a

Default Re: max of a varchar field - 10-12-2007 , 04:55 AM




"Laurenz Albe" <invite (AT) spam (DOT) to.invalid> ha scritto nel messaggio
news:1192175917.122666 (AT) proxy (DOT) dienste.wien.at...
Quote:
Dade <cucca77NOSPAM (AT) nospamgmail (DOT) com> wrote:
i have a problem with the max value of a varchar field

id docno description
=================
1 2 test1
2 F10 test2


select max(docno::text) as "docno" from table

I woul like that it returns me F10, but it doesn't... how can i tell him
to
give me the max value without consider the char part?

You'll have to strip out the letters and convert to integer before
computing the maximum. Something like this:

SELECT max(regexp_replace(docno, '[^[:digit:]]', '', 'g')::integer)
FROM "table"

Yours,
Laurenz Albe
Great! Now works perfectly!!!

thanx
Dade



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.