Okay, I have a basic test passing:
@Test void testJsonObjectPostgres() {
String query = "select json_object(\"product_name\": \"product_id\") from
\"product\"";
final String expected = "SELECT "
+ "JSON_BUILD_OBJECT('product_name',
\"product_id\")\n"
+ "FROM \"foodmart\".\"product\"";
sql(query).withPostgresql().ok(expected);
}
I did it by adding the following to "PostgresSqlDialect.java"
in the "unparseCall()" method. Not sure how "proper" this is:
case OTHER_FUNCTION:
SqlOperator operator = call.getOperator();
if (operator instanceof SqlJsonObjectFunction) {
assert call.operandCount() % 2 == 1;
final SqlWriter.Frame frame = writer.startFunCall("JSON_BUILD_OBJECT");
SqlWriter.Frame listFrame = writer.startList("", "");
for (int i = 1; i < call.operandCount(); i += 2) {
writer.literal("'" + call.operand(i).toString() + "'");
writer.sep(",", true);
call.operand(i + 1).unparse(writer, leftPrec, rightPrec);
}
writer.endList(listFrame);
writer.endFunCall(frame);
}
break;
On Fri, Feb 25, 2022 at 2:33 PM Gavin Ray <[email protected]> wrote:
> It looks like this can be done through:
>
> "SqlDialect#unparseCall(SqlWriter writer, SqlCall call, int leftPrec, int
> rightPrec)"
>
> Hopefully I am on the right track here :sweat_smile:
>