-1

I have a basic tables of books like so:

CREATE TABLE books (
  id integer primary key,
  name text not null
);
INSERT INTO books (id, name) VALUES (1, 'The Ghost');

I want to search for a book name which matches the search term ^The Ghost$. As you can see there is some regular expression in the term. How do I match via the regular expression?

I tried doing this but I got no results

select *
from books
WHERE name like '%^The Ghost$%'

SQL fiddle: http://sqlfiddle.com/#!17/8a5aa6/1

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
Paul
  • 107
  • 1
  • 1
  • 6

1 Answers1

0

Well if your requirement really be verbatim to match ^The Ghost$, then you may just use an equality comparison here:

SELECT *
FROM books
WHERE name = 'The Ghost';

If you wanted to express the above using regex, you could use the ~ operator:

SELECT *
FROM books
WHERE name ~ '^The Ghost$';
Tim Biegeleisen
  • 451,927
  • 24
  • 239
  • 318