Skip to content

Instantly share code, notes, and snippets.

@spektom
Created April 12, 2018 10:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save spektom/d29b74ee24f6fcbecb940b79cb4936cf to your computer and use it in GitHub Desktop.
Save spektom/d29b74ee24f6fcbecb940b79cb4936cf to your computer and use it in GitHub Desktop.
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