Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News SQLite 3.9 Supports JSON, Indexes on Expressions and More

SQLite 3.9 Supports JSON, Indexes on Expressions and More

This item in japanese

Recently released SQLite 3.9 provides a number of new features and enhancements, including support for JSON encoding/decoding, full text search version 5, indexes on expressions, eponymous virtual tables and more.

According to the newly adopted semantic versioning standard, SQLite 3.9 is a new version that includes changes that break forward compatibility by introducing new features, while being backward compatible with older versions. Among the new features that SQLite 3.9 introduces:

  • JSON support through the json1 extension that implements a set of functions to validate JSON strings, construct JSON arrays and objects, manipulate JSON strings by updating, inserting, or replacing values, etc. Additionally, two table-valued functions allow to transform a JSON string into a virtual table with each JSON element mapped to a row.
  • Indexes on expressions, which complement the traditional indexes that reference table columns and allow to define indexes on expressions involving columns. This features would allow to efficiently perform queries, e.g., to list all changes to a given account number that amount to more than a given quantity:
    CREATE INDEX account_change_magnitude ON account_change(acct_no, abs(amt)); SELECT * FROM account_change WHERE acct_no=$xyz AND abs(amt)>=10000; 
  • Eponymous virtual tables, which are virtual tables that can be used by simply referring their module name, i.e., without running CREATE VIRTUAL TABLE. An example of this is the dbstat virtual table, which provides low-level information about btree and overflow pages in a database file.
  • Full text search version 5 (FTS5), a virtual table module that allows to create a virtual table that can be later full-text searched. This is how you can populate a virtual table through FTS5:
    CREATE VIRTUAL TABLE email USING fts5(sender, title, body); 
    Once you have an FTS5 virtual table, you can search a term in it in three different ways:
    SELECT * FROM email WHERE email MATCH 'fts5'; SELECT * FROM email WHERE email = 'fts5'; SELECT * FROM email('fts5'); 
    This feature is still considered experimental.

Other changes worth mentioning are the addition of an optional list of column names when using CREATE_VIEW, the possibility of referencing undefined tables when creating a VIEW and having them checked at query-time.

For more details, check SQLite 3.9.0 and 3.9.1 release notes.

Rate this Article