Skip to content

Commit

Permalink
Merge pull request #2216 from taozhi8833998/refactor-ife-create-index-pg
Browse files Browse the repository at this point in the history
refactor: support if not exists stmt in create index stmt in pg
  • Loading branch information
taozhi8833998 authored Nov 13, 2024
2 parents a1cd202 + d4300ba commit 4052b28
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pegjs/postgresql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,7 @@ create_index_stmt
= a:KW_CREATE __
kw:KW_UNIQUE? __
t:KW_INDEX __
ife:if_not_exists_stmt?
co:KW_CONCURRENTLY? __
n:ident? __
on:KW_ON __
Expand All @@ -1074,6 +1075,7 @@ create_index_stmt
export interface create_index_stmt_node {
type: 'create';
index_type?: 'unique';
if_not_exists: if_not_exists_stmt;
keyword: 'index';
concurrently?: 'concurrently';
index: string;
Expand All @@ -1097,6 +1099,7 @@ create_index_stmt
keyword: t.toLowerCase(),
concurrently: co && co.toLowerCase(),
index: n,
if_not_exists: ife,
on_kw: on[0].toLowerCase(),
table: ta,
index_using: um,
Expand Down Expand Up @@ -1749,7 +1752,7 @@ ALTER_ADD_COLUMN
action: 'add';
keyword: KW_COLUMN;
resource: 'column';
if_not_exists: ife;
if_not_exists: if_not_exists_stmt;
type: 'alter';
} & create_column_definition;
*/
Expand Down
7 changes: 7 additions & 0 deletions test/postgres.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,13 @@ describe('Postgres', () => {
`SELECT start_time::TIMESTAMP AT TIME ZONE 'UTC' AS "start_time" FROM "my_table"`
]
},
{
title: 'create index with if not exists',
sql: [
'CREATE UNIQUE INDEX IF NOT EXISTS public_i_locations_pkey ON public.i_locations (id);',
'CREATE UNIQUE INDEX IF NOT EXISTS "public_i_locations_pkey" ON "public"."i_locations" (id)'
]
},
]
function neatlyNestTestedSQL(sqlList){
sqlList.forEach(sqlInfo => {
Expand Down

0 comments on commit 4052b28

Please sign in to comment.