Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions __fixtures__/generated/generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
"pretty/misc-15.sql": "ALTER DEFAULT PRIVILEGES IN SCHEMA dashboard_jobs \n GRANT EXECUTE ON FUNCTIONS TO administrator",
"pretty/misc-16.sql": "GRANT EXECUTE ON FUNCTION dashboard_private.uuid_generate_seeded_uuid TO PUBLIC",
"pretty/misc-17.sql": "SELECT CAST(t.date AT TIME ZONE $$America/New_York$$ AS text)::date FROM tbl t",
"pretty/misc-18.sql": "FETCH ALL FROM c",
"pretty/misc-19.sql": "MOVE BACKWARD ALL IN c",
"pretty/formatting-1.sql": "EXPLAIN (COSTS OFF) SELECT * FROM onek2 WHERE unique2 = 11 AND stringu1 = 'ATAAAA'",
"pretty/formatting-2.sql": "EXPLAIN SELECT * FROM onek2 WHERE unique2 = 11 AND stringu1 = 'ATAAAA'",
"pretty/formatting-3.sql": "INSERT INTO objects.object (name, val, active, hash)\nVALUES ('name', 'val', 't'::boolean, 'abcdefg'),\n ('name', 'val', 't'::boolean, 'abcdefg'),\n ('name', 'val', 't'::boolean, 'abcdefg')",
Expand Down
7 changes: 6 additions & 1 deletion __fixtures__/kitchen-sink/pretty/misc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,9 @@ GRANT EXECUTE ON FUNCTION dashboard_private.uuid_generate_seeded_uuid TO PUBLIC;


-- https://github.com/constructive-io/pgsql-parser/issues/217
SELECT CAST(t.date AT TIME ZONE $$America/New_York$$ AS text)::date FROM tbl t;
SELECT CAST(t.date AT TIME ZONE $$America/New_York$$ AS text)::date FROM tbl t;

-- FETCH/MOVE ALL (FETCH_ALL is 2147483647 in the WASM AST)
FETCH ALL FROM c;

MOVE BACKWARD ALL IN c;
4 changes: 3 additions & 1 deletion packages/deparser/__tests__/kitchen-sink/pretty-misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ it('pretty-misc', async () => {
"pretty/misc-14.sql",
"pretty/misc-15.sql",
"pretty/misc-16.sql",
"pretty/misc-17.sql"
"pretty/misc-17.sql",
"pretty/misc-18.sql",
"pretty/misc-19.sql"
]);
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ exports[`non-pretty: pretty/misc-16.sql 1`] = `"GRANT EXECUTE ON FUNCTION dashbo

exports[`non-pretty: pretty/misc-17.sql 1`] = `"SELECT CAST((t.date AT TIME ZONE 'America/New_York')::text AS date) FROM tbl AS t"`;

exports[`non-pretty: pretty/misc-18.sql 1`] = `"FETCH FORWARD ALL c"`;

exports[`non-pretty: pretty/misc-19.sql 1`] = `"MOVE BACKWARD ALL c"`;

exports[`pretty: pretty/misc-1.sql 1`] = `
"WITH
recent_orders AS (SELECT
Expand Down Expand Up @@ -302,3 +306,7 @@ exports[`pretty: pretty/misc-17.sql 1`] = `
"SELECT CAST((t.date AT TIME ZONE 'America/New_York')::text AS date)
FROM tbl AS t"
`;

exports[`pretty: pretty/misc-18.sql 1`] = `"FETCH FORWARD ALL c"`;

exports[`pretty: pretty/misc-19.sql 1`] = `"MOVE BACKWARD ALL c"`;
2 changes: 2 additions & 0 deletions packages/deparser/__tests__/pretty/misc-pretty.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const testCases = [
'pretty/misc-15.sql',
'pretty/misc-16.sql',
'pretty/misc-17.sql',
'pretty/misc-18.sql',
'pretty/misc-19.sql',
];

const prettyTest = new PrettyTest(testCases);
Expand Down
5 changes: 3 additions & 2 deletions packages/deparser/src/deparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7904,8 +7904,9 @@ export class Deparser implements DeparserVisitor {
FetchStmt(node: t.FetchStmt, context: DeparserContext): string {
const output: string[] = [node.ismove ? 'MOVE' : 'FETCH'];

// Check if howMany represents "ALL" (PostgreSQL uses LONG_MAX as sentinel)
const isAll = (node.howMany as any) === 9223372036854776000;
// FETCH_ALL is LONG_MAX: 2^63-1 from a 64-bit libpg_query, 2^31-1 from the 32-bit WASM build
const howMany = node.howMany as any;
const isAll = howMany === 9223372036854776000 || howMany === 2147483647;

// Handle direction first, then check for ALL within each direction
if (node.direction) {
Expand Down
Loading