6

I'm trying to create a database table using the sqlite3 npm package. I'd like the table to have two columns, number and colour. Number should be an integer and colour should contain json data.

Is there anyway to explicitly set the data type to json in sqlite3?

Something like this below:

db.run('CREATE TABLE table1 ( number integer, colour json)');
1
  • As of sqlite version 3.45 (pending), there will be JSONB support (like PostgreSQL) See: sqlite.org/jsonb.html Commented Jul 9, 2024 at 9:56

1 Answer 1

6

While sqlite has functions for working with JSON data (Assuming the standard JSON1 extension is enabled in the instance of the library that you're using, of course), it does not have an actual JSON type. Instead, use TEXT columns to hold JSON text like you would any other string.

More reading on the data types that sqlite supports and how unknown types are treated in table defintions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.