SELECT in VCHAR column for strings with TAB

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

SELECT in VCHAR column for strings with TAB

Matthias Apitz

Hello,

I want to search in a VCHAR column for a string with two TAB at the end.
I tried some things w/o any luck, like:

select * from acq_vardata where name=concat('Test202112', 9, 9);
select * from acq_vardata where name=concat('Test202112', '\t\t');

Any ideas? Thx

        matthias
--
Matthias Apitz, ✉ [hidden email], http://www.unixarea.de/ +49-176-38902045
Public GnuPG key: http://www.unixarea.de/key.pub
¡Con Cuba no te metas!  «»  Don't mess with Cuba!  «»  Leg Dich nicht mit Kuba an!
http://www.cubadebate.cu/noticias/2020/12/25/en-video-con-cuba-no-te-metas/


Reply | Threaded
Open this post in threaded view
|

Re: SELECT in VCHAR column for strings with TAB

Ray O'Donnell
On 10/06/2021 14:30, Matthias Apitz wrote:
>
> Hello,
>
> I want to search in a VCHAR column for a string with two TAB at the end.
> I tried some things w/o any luck, like:
>
> select * from acq_vardata where name=concat('Test202112', 9, 9);
> select * from acq_vardata where name=concat('Test202112', '\t\t');

Maybe use a regular expression?

https://www.postgresql.org/docs/13/functions-matching.html


Ray.

--
Raymond O'Donnell // Galway // Ireland
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: SELECT in VCHAR column for strings with TAB

Tom Lane-2
In reply to this post by Matthias Apitz
Matthias Apitz <[hidden email]> writes:
> I want to search in a VCHAR column for a string with two TAB at the end.
> I tried some things w/o any luck, like:

> select * from acq_vardata where name=concat('Test202112', 9, 9);
> select * from acq_vardata where name=concat('Test202112', '\t\t');

By default, backslash is not magic in SQL literals.  The right way
to spell that is something like

select * from acq_vardata where name = E'Test202112\t\t';

See the discussion of "escape strings" in

https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS

                        regards, tom lane