Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

69
Vistas
LIKE clause with \ character in PostgreSQL

I have this behavior in PostgreSQL 9.3:

-- (1) this "doesn't" work
select 't\om' like '%t\om%'
-- result = false

-- (2) this works
select 't/om' like '%t/om%'
-- result = true

Why is the (1) query result false? What is the best way to get true in (1) query?

8 months ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

The \ has no special meaning in SQL except inside the condition for the LIKE operator where it can be used to escape the wildcard characters.

But you can define a different escape character for LIKE which then makes the \ a "normal" character:

select 't\om' like '%t\om%' escape '#';

edit

As Sunrelax has commented, you can also use an empty string as the "escape" sequence:

select 't\om' like '%t\om%' escape '';
8 months ago · Santiago Trujillo Denunciar

0

\ is an escape sequence, so you need to escape it, too:

select 't\om' like '%t\\om%';

There is also a configuration option you can set. See Escaping backslash in Postgresql

8 months 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 empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.