jsonFuncReturnsNonJSON reports whether a json*-named function returns a non-JSON value (VARCHAR, BIGINT, BOOLEAN, ...), so its result concatenated with || must keep DuckDB string-concat semantics. Covers both the PostgreSQL names and the DuckDB names FunctionTransform rewrites them to (function mapp
(name string)
| 698 | // names and the DuckDB names FunctionTransform rewrites them to (function |
| 699 | // mapping runs before this transform in the pipeline). |
| 700 | func jsonFuncReturnsNonJSON(name string) bool { |
| 701 | for _, suffix := range []string{"_string", "_text", "_length", "_keys", "_valid", "_exists", "_contains"} { |
| 702 | if strings.HasSuffix(name, suffix) { |
| 703 | return true |
| 704 | } |
| 705 | } |
| 706 | switch name { |
| 707 | case "json_type", "json_typeof", "jsonb_typeof": |
| 708 | return true |
| 709 | } |
| 710 | return false |
| 711 | } |
| 712 | |
| 713 | // createJSONConcatExpr rewrites `a || b` (with a JSON-looking operand) to a |
| 714 | // CASE expression reproducing Postgres jsonb || semantics in DuckDB: |