pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
SQL Question about like
7+ messages / 4 participants
[nested] [flat]

* SQL Question about like
@ 2020-08-10 16:37 pgml@gmx.de <pgml@gmx.de>
  2020-08-10 16:48 ` Re: SQL Question about like Ron <ronljohnsonjr@gmail.com>
  2020-08-10 16:51 ` Re: SQL Question about like Adrian Klaver <adrian.klaver@aklaver.com>
  2020-08-10 17:01 ` Re: SQL Question about like Michael Nolan <htfoot@gmail.com>
  0 siblings, 3 replies; 7+ messages in thread

From: pgml@gmx.de @ 2020-08-10 16:37 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Hello,

my SQL question is, why psql doesn't return the record?

create table lll (text char(100));
insert into lll (text) values ('10% - Ersthelfer');

select * from lll where text like '10% - Ersthelfer';

Other databases (Maria, SQL Server, YARD) do this.
What can I do in pg, to get the result?

Thank you and best regards, Martin






^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: SQL Question about like
  2020-08-10 16:37 SQL Question about like pgml@gmx.de <pgml@gmx.de>
@ 2020-08-10 16:48 ` Ron <ronljohnsonjr@gmail.com>
  2 siblings, 0 replies; 7+ messages in thread

From: Ron @ 2020-08-10 16:48 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 8/10/20 11:37 AM, pgml@gmx.de wrote:
> Hello,
>
> my SQL question is, why psql doesn't return the record?
>
> create table lll (text char(100));
> insert into lll (text) values ('10% - Ersthelfer');
>
> select * from lll where text like '10% - Ersthelfer';
>
> Other databases (Maria, SQL Server, YARD) do this.
> What can I do in pg, to get the result?

Add a wildcard character.  (Also, why use LIKE in an equality?)

test=# select * from lll where text like '10% - Ersthelfer';
  text
------
(0 rows)

test=# select * from lll where text like '10% - Ersthelfer%';
text
--------------------------------------------------------------
  10% - Ersthelfer
(1 row)

test=#
test=#
test=# select * from lll where text = '10% - Ersthelfer';
text
--------------------------------------------------------------
  10% - Ersthelfer
(1 row)


-- 
Angular momentum makes the world go 'round.

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: SQL Question about like
  2020-08-10 16:37 SQL Question about like pgml@gmx.de <pgml@gmx.de>
@ 2020-08-10 16:51 ` Adrian Klaver <adrian.klaver@aklaver.com>
  2 siblings, 0 replies; 7+ messages in thread

From: Adrian Klaver @ 2020-08-10 16:51 UTC (permalink / raw)
  To: pgml@gmx.de <pgml@gmx.de>; pgsql-general@lists.postgresql.org

On 8/10/20 9:37 AM, pgml@gmx.de wrote:
> Hello,
> 
> my SQL question is, why psql doesn't return the record?
> 
> create table lll (text char(100));
> insert into lll (text) values ('10% - Ersthelfer');
> 
> select * from lll where text like '10% - Ersthelfer';
> 
> Other databases (Maria, SQL Server, YARD) do this.
> What can I do in pg, to get the result?

A little documentation goes a long way:) :

https://www.postgresql.org/docs/12/functions-matching.html#FUNCTIONS-LIKE
> 
> Thank you and best regards, Martin
> 
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: SQL Question about like
  2020-08-10 16:37 SQL Question about like pgml@gmx.de <pgml@gmx.de>
@ 2020-08-10 17:01 ` Michael Nolan <htfoot@gmail.com>
  2020-08-10 17:24   ` Re: SQL Question about like Adrian Klaver <adrian.klaver@aklaver.com>
  2 siblings, 1 reply; 7+ messages in thread

From: Michael Nolan @ 2020-08-10 17:01 UTC (permalink / raw)
  To: pgml@gmx.de <pgml@gmx.de>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

The problem is your field is fixed length text, change it to varchar(100)
or text and it works without the wildcard at the end.
--
Mike Nolan

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: SQL Question about like
  2020-08-10 16:37 SQL Question about like pgml@gmx.de <pgml@gmx.de>
  2020-08-10 17:01 ` Re: SQL Question about like Michael Nolan <htfoot@gmail.com>
@ 2020-08-10 17:24   ` Adrian Klaver <adrian.klaver@aklaver.com>
  2020-08-10 17:44     ` Re: SQL Question about like Michael Nolan <htfoot@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Adrian Klaver @ 2020-08-10 17:24 UTC (permalink / raw)
  To: Michael Nolan <htfoot@gmail.com>; pgml@gmx.de <pgml@gmx.de>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

On 8/10/20 10:01 AM, Michael Nolan wrote:
> The problem is your field is fixed length text, change it to 
> varchar(100) or text and it works without the wildcard at the end.

That assumes values don't get entered  with spaces:

create table lll (text varchar(100));
insert into lll (text) values ('10% - Ersthelfer');
insert into lll (text) values ('10% - Ersthelfer   ');

select * from lll where text like '10% - Ersthelfer';
        text
------------------
  10% - Ersthelfer
(1 row)

select * from lll where text like '10% - Ersthelfer%';
         text
---------------------
  10% - Ersthelfer
  10% - Ersthelfer

I have seen that enough times to default to using wildcard if I am 
really looking for LIKE not =.

> --
> Mike Nolan
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: SQL Question about like
  2020-08-10 16:37 SQL Question about like pgml@gmx.de <pgml@gmx.de>
  2020-08-10 17:01 ` Re: SQL Question about like Michael Nolan <htfoot@gmail.com>
  2020-08-10 17:24   ` Re: SQL Question about like Adrian Klaver <adrian.klaver@aklaver.com>
@ 2020-08-10 17:44     ` Michael Nolan <htfoot@gmail.com>
  2020-08-10 17:49       ` Re: SQL Question about like Michael Nolan <htfoot@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Michael Nolan @ 2020-08-10 17:44 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: pgml@gmx.de <pgml@gmx.de>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

I usually use something like trim(field) like 'pattern'.  Eliminates the
need for the wildcard at the end.  I find I use the ~ operator more than
'like' though.
--
Mike Nolan

On Mon, Aug 10, 2020 at 12:24 PM Adrian Klaver <adrian.klaver@aklaver.com>
wrote:

> On 8/10/20 10:01 AM, Michael Nolan wrote:
> > The problem is your field is fixed length text, change it to
> > varchar(100) or text and it works without the wildcard at the end.
>
> That assumes values don't get entered  with spaces:
>
> create table lll (text varchar(100));
> insert into lll (text) values ('10% - Ersthelfer');
> insert into lll (text) values ('10% - Ersthelfer   ');
>
> select * from lll where text like '10% - Ersthelfer';
>         text
> ------------------
>   10% - Ersthelfer
> (1 row)
>
> select * from lll where text like '10% - Ersthelfer%';
>          text
> ---------------------
>   10% - Ersthelfer
>   10% - Ersthelfer
>
> I have seen that enough times to default to using wildcard if I am
> really looking for LIKE not =.
>
> > --
> > Mike Nolan
> >
> >
>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com
>

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: SQL Question about like
  2020-08-10 16:37 SQL Question about like pgml@gmx.de <pgml@gmx.de>
  2020-08-10 17:01 ` Re: SQL Question about like Michael Nolan <htfoot@gmail.com>
  2020-08-10 17:24   ` Re: SQL Question about like Adrian Klaver <adrian.klaver@aklaver.com>
  2020-08-10 17:44     ` Re: SQL Question about like Michael Nolan <htfoot@gmail.com>
@ 2020-08-10 17:49       ` Michael Nolan <htfoot@gmail.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Michael Nolan @ 2020-08-10 17:49 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: pgml@gmx.de <pgml@gmx.de>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

>
> Sorry about the top-posting, Firefox and I disagreed about whether I was
> done editing the previous message.
>
--
Mike Nolan

^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2020-08-10 17:49 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-08-10 16:37 SQL Question about like pgml@gmx.de <pgml@gmx.de>
2020-08-10 16:48 ` Ron <ronljohnsonjr@gmail.com>
2020-08-10 16:51 ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-08-10 17:01 ` Michael Nolan <htfoot@gmail.com>
2020-08-10 17:24   ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-08-10 17:44     ` Michael Nolan <htfoot@gmail.com>
2020-08-10 17:49       ` Michael Nolan <htfoot@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox