Live data from Hacker News

JSON with Sqlite

sqlite.org

1–10 of 74 posts

Re: JSON with Sqlite

#4
What are some useful use-cases for this?

I can already use JSON in Sqlite by doing parsing in the client outside of the Sqlite API. Any examples where I'd want to use this instead? I'm guessing for where clauses in queries, perhaps?

Can I create an index on a field within a JSON tuple?

Re: JSON with Sqlite

#5
post #4

What are some useful use-cases for this? I can already use JSON in Sqlite by doing parsing in the client outside of the Sqlite API. Any examples where I'd want to use this instead? I'm guessing for where clauses in queries, perhaps? Can I create an index on a field within a JSON tuple?

Since you can make effectively arbitrary index expressions[1], I'd expect the answer to be "yes". The article doesn't explicitly state if they're deterministic or not, but it seems like some of them could / should be.

[1]: https://www.sqlite.org/expridx.html

Re: JSON with Sqlite

#6
post #2

Is loading extensions at runtime new? Coulda sworn I used to have to recompile for this

It seems valuable enough to have in the standard build. That and the CSV extension as well.

Re: JSON with Sqlite

#8
post #5
post #4

What are some useful use-cases for this? I can already use JSON in Sqlite by doing parsing in the client outside of the Sqlite API. Any examples where I'd want to use this instead? I'm guessing for where clauses in queries, perhaps? Can I create an index on a field within a JSON tuple?

Since you can make effectively arbitrary index expressions[1], I'd expect the answer to be "yes". The article doesn't explicitly state if they're deterministic or not, but it seems like some of them could / should be. [1]: https://www.sqlite.org/expridx.html

I gave it a shot and it appears to work as expected.

  sqlite> create table a (id int primary key, j json);
  sqlite> insert into a values (1, '{"hello":"world"}');
  sqlite> create index idx_a on a (json_extract(j, '$.hello'));
  sqlite> explain query plan select * from a where json_extract(j, '$.hello') = 'world';
  QUERY PLAN
  `--SEARCH TABLE a USING INDEX idx_a (=?)
  sqlite> explain query plan select * from a where json_extract(j, '$.foo') = 'world';
  QUERY PLAN
  `--SCAN TABLE a

Re: JSON with Sqlite

#10
post #4

What are some useful use-cases for this? I can already use JSON in Sqlite by doing parsing in the client outside of the Sqlite API. Any examples where I'd want to use this instead? I'm guessing for where clauses in queries, perhaps? Can I create an index on a field within a JSON tuple?

[deleted]
Post reply on HN