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

405
Vistas
Extract Substring in Comma Separated values in Postgresql

Two Variables in Postgresql:

V_VAR :='US185268001,US285268002,US385268005'; --Input
V_OUT := '001,002,005'; --Expected output to be stored

Any idea how to do in postgresql? Last 3 characters of each comma separated value. How to manipulate the V_VAR variable to get the output as V_OUT variable.

Update:

Please Note: V_VAR can have any number of CSV list. Here i have 3 values for the example purpose.

Thanks, Karthik

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

0

We can try using a regex replacement here:

SELECT
    col,
    REGEXP_REPLACE(col, '.*?([0-9]{3})(,|$)', '\1\2', 'g') AS col_out
FROM yourTable;

The strategy here is to match lazily until matching (and capturing) the final 3 digits of each code in one group, and an optional comma in a second group. Then, we replace with just the three digits and optional comma separator.

Note: As @BillKarvin has pointed out, storing unnormalized CSV is not optimal database design. Please consider getting each code onto a separate record if possible.

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