Created
April 12, 2018 10:58
-
-
Save spektom/d29b74ee24f6fcbecb940b79cb4936cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE bookdata ( | |
id serial NOT NULL PRIMARY KEY, | |
info json NOT NULL | |
) | |
CREATE INDEX bookdata_fts ON bookdata USING gin((to_tsvector('english',info->'title'))); | |
INSERT INTO bookdata (info) | |
VALUES | |
( '{ "title": "The Tattooed Duke", "items": {"product": "Diaper","qty": 24}}'), | |
( '{ "title": "She Tempts the Duke", "items": {"product": "Toy Car","qty": 1}}'), | |
( '{ "title": "The Duke Is Mine", "items": {"product": "Toy Train","qty": 2}}'), | |
( '{ "title": "What I Did For a Duke", "items": {"product": "Toy Train","qty": 2}}'), | |
('{ "title": "King Kong", "items": {"product": "Toy Train","qty": 2}}'); | |
SELECT info -> 'title' as title FROM bookdata | |
WHERE to_tsvector('english',info->'title') @@ to_tsquery('Duke'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment