Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

143
Vistas
PostgreSQL order by, numbers last

name2 could be string or number. I.e. 'one two' or 12

I would like to order names so that numbers to be last, i.e:

a a
b b
one two
1
22
select name1, name2 
from names 
order by name2

Q: how one would do it?

P.S. in oracle it is like this.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You can use REGEXP_REPLACE() function with '[^[:digit:]]*' posix, to determine whether the string has a digit or not in it, including an asterisk at the end to anchor a regular expression to the end of the source text :

SELECT name2
  FROM t
 ORDER BY REGEXP_REPLACE(name2,'[^[:digit:]]*',''), name2

Demo

over 4 years ago · Santiago Trujillo Denunciar

0

You can use a boolean expression in order by, e.g.:

select name1, name2 
from names 
order by left(name2, 1) <= '9', name2

Db<>fiddle.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda