8000 fix: support create index if not exists by tomquist · Pull Request #135 · launchql/pgsql-parser · GitHub
[go: up one dir, main page]

Skip to content
8000

fix: support create index if not exists #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2025
Merged
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
fix: support create index if not exists
The flag `if_not_exists` was ignored when deparsing a create index
statement.
  • Loading branch information
tomquist committed May 28, 2025
commit 60f309f6c83bf30ba7b6858dbf2afbbaf4b648c4
4 changes: 3 additions & 1 deletion __fixtures__/misc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ create table if not exists users (
handle text not null,
created_at timestamp not null default now(),
updated_at timestamp not null default now()
)
);

CREATE INDEX CONCURRENTLY IF NOT EXISTS index_email_logs_on_created_at ON public.email_logs USING btree (created_at DESC);
Original file line number Diff line number Diff line change
Expand Up @@ -246734,7 +246734,7 @@ exports[`misc 15`] = `
],
},
},
"stmt_len": undefined,
"stmt_len": 238,
"stmt_location": 629,
},
}
Expand All @@ -246747,9 +246747,44 @@ name text NOT NULL,
handle text NOT NULL,
created_at timestamp NOT NULL DEFAULT ( now() ),
updated_at timestamp NOT NULL DEFAULT ( now() )
)"
);"
`;

exports[`misc 17`] = `
{
"RawStmt": {
"stmt": {
"IndexStmt": {
"accessMethod": "btree",
"concurrent": true,
"idxname": "index_email_logs_on_created_at",
"if_not_exists": true,
"indexParams": [
{
"IndexElem": {
"name": "created_at",
"nulls_ordering": "SORTBY_NULLS_DEFAULT",
"ordering": "SORTBY_DESC",
},
},
],
"relation": {
"inh": true,
"location": 944,
"relname": "email_logs",
"relpersistence": "p",
"schemaname": "public",
},
},
},
"stmt_len": 123,
"stmt_location": 868,
},
}
`;

exports[`misc 18`] = `"CREATE INDEX CONCURRENTLY IF NOT EXISTS index_email_logs_on_created_at ON public.email_logs ( created_at DESC );"`;

exports[`parens 1`] = `
{
"RawStmt": {
Expand Down
3 changes: 3 additions & 0 deletions packages/deparser/src/deparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,9 @@ export default class Deparser {
if (node.concurrent) {
output.push('CONCURRENTLY');
}
if (node.if_not_exists) {
output.push('IF NOT EXISTS');
}

if (node.idxname) {
output.push(node.idxname);
Expand Down
0