Repository navigation
JSONB aggregate results are displayed differently in sqlite-jdbc and SQLite Fiddle #1479
Describe the bugI observed inconsistent representations of JSONB aggregate function results between SQLite Fiddle and sqlite-jdbc. For the same SQL queries, SQLite Fiddle displays the decoded JSON array, whereas sqlite-jdbc exposes the binary JSONB representation, which may appear as raw characters or hexadecimal data. This discrepancy can make equivalent results appear different to users and applications, particularly when JSONB values are retrieved or displayed as strings. To ReproduceCase 1: JSONB_GROUP_ARRAY with a string literal SELECT JSONB_GROUP_ARRAY('Ia');Observed results:
The hexadecimal representation of the JSONB value is: Case 2: JSONB_GROUP_ARRAY with a scalar subquery SELECT JSONB_GROUP_ARRAY(
(SELECT CAST(json('Ia' AND 'Ia') AS TEXT)
FROM (SELECT 1 AS k)
WHERE k = 1
ORDER BY k)
);Observed results:
The hexadecimal value Expected behaviorI would like clarification on the expected JDBC behavior when retrieving JSONB aggregate results. Ideally, applications should have a documented and consistent way to retrieve JSONB results in a human-readable JSON format, such as If the driver intentionally exposes JSONB values as BLOBs, it would be helpful to clarify the appropriate retrieval method and whether LogsNo exception is thrown. The issue concerns the representation of returned JSONB values. Environment
Additional contextAccording to the SQLite JSON1 documentation, the Therefore, the observed differences may reflect distinct result-rendering or JDBC conversion behaviors rather than different SQL evaluation results. The purpose of this report is to clarify whether sqlite-jdbc's JSONB result handling is intentional and whether a more consistent or explicitly documented JSONB-to-text retrieval mechanism should be provided. |
Replies: 3 comments 1 reply
|
It seems SQLite Fiddle uses the sqlite CLI, which has different rendering. This is not comparable. |
|
SQLite Fiddle is merely a presentation method. What I actually meant to say is that there is a significant difference in the performance between these two. For example, SELECT JSONB_GROUP_ARRAY((SELECT CAST((json((((('Ia'))) AND ('Ia')))) AS TEXT)) SELECT JSONB_GROUP_ARRAY((SELECT CAST((json((((('Ia'))) AND ('Ia')))) AS TEXT) These two queries resulted in the following outcomes: 0x2B1330 and 0x2B1730. |
|
The two hex values in your follow-up represent different JSON values, not just different display formats. I checked them with SQLite 3.53.1: SELECT json(x'2B1330'), json(x'2B1730');
-- [0] ["0"]The first contains a JSON number; the second contains a JSON string. That is separate from the original JDBC-versus-Fiddle rendering question. For human-readable JDBC output, convert explicitly in SQL and then use SELECT json(jsonb_group_array('Ia'));
-- ["Ia"]Use To investigate the two query variants, compare References: JSON value arguments and JSONB, JSONB encoding. |
This has been confirmed as a bug and has been fixed: https://sqlite.org/src/info/8ab55e0185a1956f