Skip to content

Commit d896b46

Browse files
authored
Merge pull request #4 from 1ilit/create-index
add create index on table
2 parents 5f6662c + 8b5359c commit d896b46

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

src/pegjs/oracle.pegjs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,50 @@ stmt
153153
/ create_sequence_stmt
154154
/ alter_sequence_stmt
155155
/ drop_sequence_stmt
156+
/ create_index_stmt
157+
158+
// TODO: missing index_ilm_clause, cluster_index_clause, bitmap_join_index_clause
159+
create_index_stmt
160+
= operation:KW_CREATE _
161+
type:(KW_UNIQUE / KW_BITMAP / KW_MULTIVALUE)? _
162+
object:KW_INDEX _
163+
if_not_exists:if_not_exists? _
164+
name:schema_object _ KW_ON _
165+
target:table_index_clause _
166+
usable:(KW_USABLE / KW_UNUSABLE)? _
167+
invalidation:(x:(KW_DEFERRED / KW_IMMEDIATE) _ KW_INVALIDATION { return x; })? _
168+
SEMI_COLON {
169+
return {
170+
operation,
171+
type,
172+
object,
173+
if_not_exists,
174+
name,
175+
target,
176+
usable,
177+
invalidation,
178+
};
179+
}
180+
181+
// TODO: missing index_properties
182+
table_index_clause
183+
= name:schema_object _
184+
t_alias:identifier_name? _
185+
LPAR _ columns:table_index_columns _ RPAR {
186+
return { name, t_alias, columns, object: 'table' };
187+
}
188+
189+
table_index_columns
190+
= x:table_index_column _
191+
xs:(COMMA _ c:table_index_column { return c; })* {
192+
return [x, ...xs];
193+
}
194+
195+
table_index_column
196+
= name:identifier_name _
197+
order:(KW_ASC / KW_DESC)? {
198+
return { name, order };
199+
}
156200

157201
drop_sequence_stmt
158202
= operation:KW_DROP _
@@ -2992,6 +3036,12 @@ KW_NOSCALE = 'noscale'i !ident_start { return '
29923036
KW_EXTEND = 'extend'i !ident_start { return 'extend'; }
29933037
KW_NOEXTEND = 'noextend'i !ident_start { return 'noextend'; }
29943038
KW_NOSHARED = 'noshared'i !ident_start { return 'noshared'; }
3039+
KW_BITMAP = 'bitmap'i !ident_start { return 'bitmap'; }
3040+
KW_MULTIVALUE = 'multivalue'i !ident_start { return 'multivalue'; }
3041+
KW_ASC = 'asc'i !ident_start { return 'asc'; }
3042+
KW_DESC = 'desc'i !ident_start { return 'desc'; }
3043+
KW_USABLE = 'usable'i !ident_start { return 'usable'; }
3044+
KW_INVALIDATION = 'invalidation'i !ident_start { return 'invalidation'; }
29953045
29963046
KW_VARYING = 'varying'i !ident_start { return 'varying'; }
29973047
KW_VARCHAR = 'varchar'i !ident_start { return 'varchar'; }
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const { Parser } = require("../../");
2+
3+
const parser = new Parser();
4+
5+
describe("create index statement", () => {
6+
it("create unique index some_index on some_table (col1, col2);", () => {
7+
const sql = "create unique index some_index on some_table (col1, col2);";
8+
const ast = parser.parse(sql);
9+
const expected = {
10+
operation: "create",
11+
type: "unique",
12+
object: "index",
13+
if_not_exists: null,
14+
name: {
15+
schema: null,
16+
name: "some_index",
17+
},
18+
target: {
19+
name: {
20+
schema: null,
21+
name: "some_table",
22+
},
23+
object: "table",
24+
t_alias: null,
25+
columns: [
26+
{
27+
name: "col1",
28+
order: null,
29+
},
30+
{
31+
name: "col2",
32+
order: null,
33+
},
34+
],
35+
},
36+
usable: null,
37+
invalidation: null,
38+
};
39+
expect(ast[0]).toMatchObject(expected);
40+
});
41+
});

0 commit comments

Comments
 (0)