News for hackers. Stuff that matters.
Re:JSONB Has Landed in SQLite by dheera on Wednesday December 06, 2023 @09:45AM (#38544547)
> There is no json data type

Why not? I feel like a database should allow for a JSON data type that stores only valid JSON or throws an exception. It would also be nice to be able to access subfields of the JSON.

SELECT userid, username, some_json_field["some_subfield"][0] FROM users where ...

Not sure where to give feature suggestions so I'm just leaving this here for future devs to find

Re:JSONB Has Landed in SQLite by sroussey on Wednesday December 06, 2023 @10:17AM (#38544930)
SQLite has a surprisingly small number of types: null, integer, real, text, and blob. That’s it.

https://www.sqlite.org/datatype3.html

Re:JSONB Has Landed in SQLite by mdaniel on Wednesday December 06, 2023 @12:42PM (#38547108)
The H2 database uses almost that exact syntax:

  create table foo(my_json json);
  insert into foo values ('{"a":{"b":{"c":"d"}}}' FORMAT JSON);
  select (my_json)."a"."b"."c" from foo; -- where the () around the field is mandatory
https://h2database.com/html/grammar.html#field_reference
Re:JSONB Has Landed in SQLite by chungy on Wednesday December 06, 2023 @12:45PM (#38547143)
> It would also be nice to be able to access subfields of the JSON.

Not that it's not _useful_ sometimes, but it amuses me that this is a huge violation of 1NF and people are often ok with it. It really depends on whether you're treating the JSON object as an atomic unit on its own, regardless of contents, or using the JSON to store more fine-grained information.

I guess the same argument can be made for XML data types, and everyone's OK with it too.

Re:JSONB Has Landed in SQLite by yencabulator on Wednesday December 06, 2023 @07:31PM (#38551369)
1NF is a theory construct that makes no accommodation for real-world performance. I'm shuddering even thinking how many tables and joins I would need to store some of these 3rd party JSON things I need to import & refine.
Re:JSONB Has Landed in SQLite by icedchai on Wednesday December 06, 2023 @07:07PM (#38551204)
Database design is, unfortunately, a lost art. Up through the early 2010's I remember having design reviews for database schemas, etc. That isn't "agile"... so you just fix it in the next sprint, as you explain to someone what a unique constraint is and why a table is now full of duplicates.
Re:JSONB Has Landed in SQLite by marcosdumay on Wednesday December 06, 2023 @01:29PM (#38547732)
The principles of relational algebra aren't always compatible with real applications.

They are successful beyond anything that I can imagine people expecting when creating them. But they are not that complete silver bullet that solves every problem humanity will ever need solved.

Re:JSONB Has Landed in SQLite by 0x457 on Wednesday December 06, 2023 @01:40PM (#38547863)
SQLite has a very few actual data types. There is a function that validates json and you can use it as a check on your `TEXT` or` `BLOB` column.

You can access subfields using `json_` and `jsonb_` functions.