Thread: SELECT in VCHAR column for strings with TAB

SELECT in VCHAR column for strings with TAB

From
Matthias Apitz
Date:
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, ✉ guru@unixarea.de, 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/



Re: SELECT in VCHAR column for strings with TAB

From
Ray O'Donnell
Date:
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
ray@rodonnell.ie



Re: SELECT in VCHAR column for strings with TAB

From
Tom Lane
Date:
Matthias Apitz <guru@unixarea.de> 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