Dreeww
Dreeww

Reputation: 93

Postgres Like statement won't read properly

I have been trying to figure out why this LIKE statement won't read properly.

CREATE VIEW sole_python_author(author_first_name, author_last_name,book_title)
AS SELECT
authors.first_name,authors.last_name, books.title
FROM authors, books
WHERE books.author_id = authors.author_id AND  books.title LIKE '%python%';

If i remove 'python' the sample output is this:

author_first_name | author_last_name |         book_title          
-------------------+------------------+-----------------------------
 Stephen           | King             | The Shining
 Frank             | Herbert          | Dune
 Arthur C.         | Clarke           | 2001: A Space Odyssey
 Seuss             | Theodor          | The Cat in the Hat
 Seuss             | Theodor          | Bartholomew and the Oobleck
 Paulette          | Bourgeois        | Franklin in the Dark
 Margaret Wise     | Brown            | Goodnight Moon
 Louisa May        | Alcott           | Little Women
 Margery Williams  | Bianco           | The Velveteen Rabbit
 Burne             | Hogarth          | Dynamic Anatomy
 Edgar Allen       | Poe              | The Tell-Tale Heart
 Mark              | Lutz             | Programming Python
 Mark              | Lutz             | Learning Python
 Tom               | Christiansen     | Perl Cookbook
 John              | Worsley          | Practical PostgreSQL

However, when I add 'python' to the code it returns 0 Rows. I believe the problem lies with the like statement but I'm unsure. I'm trying to get the output as follows:

 Mark              | Lutz             | Programming Python
 Mark              | Lutz             | Learning Python

or is my statement being performed correctly and the output should be 0 Rows?

Upvotes: 0

Views: 49

Answers (2)

Jay Shankar Gupta
Jay Shankar Gupta

Reputation: 6088

LIKE keyword is Case sensitive.

books.title LIKE '%Python%'

Or

LOWER(books.title) LIKE '%python%'

Or

books.title ILIKE '%python%'

Upvotes: 1

wargre
wargre

Reputation: 4753

LIKE keyword match String in a case sensitive way. I think you want to use ILIKE which is similar to LIKE but is not case sensitive.

Upvotes: 1

Related Questions