Skip to content

Add the type jsonpath - #286

Merged
tamnd merged 1 commit into
mainfrom
jp
Oct 13, 2026
Merged

tamnd merged 1 commit into
mainfrom
jp

Conversation

@tamnd

@tamnd tamnd commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Summary

This adds the type jsonpath, as jsonpath_scan.l, jsonpath_gram.y and jsonpath.c have it. The functions that execute a path, such as jsonb_path_query and the operators @? and @@, are not in this change.

Changes

  • rupg-types has the new JsonPath, PathItem and Value::JsonPath. A value is the tree of the path. The items that follow an item are in a list, so a long chain of accessors does not use deep recursion.
  • The scanner follows the rules of flex on bytes: the longest match wins and the first rule wins a tie. The text of each token is the text that flex has in yytext, so each syntax error names the same text as PostgreSQL. This includes the rules for numbers with trailing junk, names that a comment follows, and the escapes \x, \u and \u{} with pairs of surrogates.
  • The parser is a recursive descent parser that takes the same language as the grammar. It stops at the first token that the grammar cannot take, and it does the actions in the same order as bison, so the first error is the same error.
  • jsonpath_parse has the checks of flattenJsonPathParseItem for @ and last, the flags of like_regex and the check of its pattern, and the check of the arguments of .decimal().
  • jsonpath_deparse, jsonpath_send and jsonpath_recv give the text and binary forms, as printJsonPathItem writes them.
  • rupg-func has the text and binary input and output. A number that is too large and a path that is too deep are errors that pg_input_is_valid does not catch, as in PostgreSQL. The message for a code point that is too large is not the same in the soft input, as in PostgreSQL.
  • A constant of type jsonpath in a stored expression keeps the bytes of its binary form.

Known differences

  • PostgreSQL stops a path that is too deep when it reaches max_stack_depth. Here the limit is 1000 levels, as the analyzer has for an expression. The error is the same.

Tests

  • The session test jsonpath is the output of PostgreSQL 19 for the same script in a new database. It has 176 statements, and 110 of them end with an error. It has the input of each kind of item, the escapes and the comments, the errors of the scanner and the parser, the output, arrays, pg_input_is_valid, pg_input_error_info, text and binary COPY and a query with parameters.
  • Unit tests for the text form, the errors and the binary form.
  • fmt, clippy, the workspace tests and the checks of xtask pass on server1.

@tamnd tamnd added this to the M2: Connect and introspect milestone Oct 13, 2026
@tamnd tamnd added kind/feature It does not do something that it must do. gate/G1 G1: 7 clients connect and show the schema (L1, L2). area/types Types, type I/O, casts and collations. labels Oct 13, 2026
@tamnd tamnd self-assigned this Oct 13, 2026
@tamnd
tamnd merged commit ee49891 into main Oct 13, 2026
5 checks passed
@tamnd
tamnd deleted the jp branch October 13, 2026 11:37
This was referenced Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/types Types, type I/O, casts and collations. gate/G1 G1: 7 clients connect and show the schema (L1, L2). kind/feature It does not do something that it must do.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant