Skip to content

fix: keep ORDER BY, LIMIT, OFFSET and FETCH when deparsing VALUES - #2943

Open
Vineet829 wants to merge 1 commit into
JSQLParser:masterfrom
Vineet829:fix-values-deparser-order-by-limit
Open

Vineet829 wants to merge 1 commit into
JSQLParser:masterfrom
Vineet829:fix-values-deparser-order-by-limit

Conversation

@Vineet829

Copy link
Copy Markdown

SelectDeParser.visit(Values) writes the VALUES list, its WITH items (#2732) and its alias, but not the clauses that can follow it. Values.toString() prints them through Select.appendTo(), so the two outputs differ and the deparsed query loses its ordering and row limit:

Statement st = CCJSqlParserUtil.parse("VALUES (2), (1) ORDER BY 1 LIMIT 1");
st.toString();                         // VALUES (2), (1) ORDER BY 1 LIMIT 1
st.accept(new StatementDeParser(sb));  // sb: VALUES (2), (1)

A VALUES subquery such as x IN (VALUES (2), (1) ORDER BY 1 LIMIT 1) loses them the same way. This writes ORDER BY (with INTERPOLATE), LIMIT, OFFSET, FETCH and the isolation clause after the body, as visit(SetOperationList) already does. ValuesStatementDeParser used on its own still writes only the list, the WITH items and the alias. I added testOrderByLimitOffsetAndFetch to ValuesTest.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant