El 30/09/2010 18:22, Rodrigo Ruiz escribió:
Estimados,
la siguiente representa parte del resultado de una consulta sobre una
tabla y que se ordena por el campo 'indice' de forma ascendente.

# select * from tabla order by indice asc;

id | titulo | indice
----+----------+--------
106 | texto 4 | 1.1
115 | texto 13 | 1.10
116 | texto 1 | 1.11
107 | texto 5 | 1.2
108 | texto 6 | 1.3
109 | texto 7 | 1.4
110 | texto 8 | 1.5
111 | texto 9 | 1.6
112 | texto 10 | 1.7
113 | texto 11 | 1.8
114 | texto 12 | 1.9
117 | texto 2 | 2.1
118 | texto 3 | 2.2

El campo indice es un varchar, si notan, luego del punto 1.1 salta al
1.10, el cual necesito se presente siguiendo al punto 1.9.
Intenté pasando el campo a numérico con cast, sin embargo se me
complicó, pues podrían existir puntos del tipo 1.2.6 o más detallado aún.
La pregunta ya la podrán adivinar, cómo podría obtener el resultado de
la consulta de manera ordenada por índice?



select indice
from (values ('4.0.3.2'), ('1.2.3.4'), ('2.3.4.5'),
    ('20.3.1'), ('20.3'), ('4.1'), ('10.3'),
    ('0.5'), ('10.2.7')
  ) foo(indice)
order by regexp_split_to_array(indice, E'\\.')::integer[];

 indice
---------
 0.5
 1.2.3.4
 2.3.4.5
 4.0.3.2
 4.1
 10.2.7
 10.3
 20.3
 20.3.1
(9 filas)


:)

--
Oswaldo Hernández
-
Enviado a la lista de correo pgsql-es-ayuda ([email protected])
Para cambiar tu suscripci�n:
http://www.postgresql.org/mailpref/pgsql-es-ayuda

Responder a