Skip to content
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
50 changes: 50 additions & 0 deletions src/pegjs/oracle.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,50 @@ stmt
/ create_sequence_stmt
/ alter_sequence_stmt
/ drop_sequence_stmt
/ create_index_stmt

// TODO: missing index_ilm_clause, cluster_index_clause, bitmap_join_index_clause
create_index_stmt
= operation:KW_CREATE _
type:(KW_UNIQUE / KW_BITMAP / KW_MULTIVALUE)? _
object:KW_INDEX _
if_not_exists:if_not_exists? _
name:schema_object _ KW_ON _
target:table_index_clause _
usable:(KW_USABLE / KW_UNUSABLE)? _
invalidation:(x:(KW_DEFERRED / KW_IMMEDIATE) _ KW_INVALIDATION { return x; })? _
SEMI_COLON {
return {
operation,
type,
object,
if_not_exists,
name,
target,
usable,
invalidation,
};
}

// TODO: missing index_properties
table_index_clause
= name:schema_object _
t_alias:identifier_name? _
LPAR _ columns:table_index_columns _ RPAR {
return { name, t_alias, columns, object: 'table' };
}

table_index_columns
= x:table_index_column _
xs:(COMMA _ c:table_index_column { return c; })* {
return [x, ...xs];
}

table_index_column
= name:identifier_name _
order:(KW_ASC / KW_DESC)? {
return { name, order };
}

drop_sequence_stmt
= operation:KW_DROP _
Expand Down Expand Up @@ -2992,6 +3036,12 @@ KW_NOSCALE = 'noscale'i !ident_start { return '
KW_EXTEND = 'extend'i !ident_start { return 'extend'; }
KW_NOEXTEND = 'noextend'i !ident_start { return 'noextend'; }
KW_NOSHARED = 'noshared'i !ident_start { return 'noshared'; }
KW_BITMAP = 'bitmap'i !ident_start { return 'bitmap'; }
KW_MULTIVALUE = 'multivalue'i !ident_start { return 'multivalue'; }
KW_ASC = 'asc'i !ident_start { return 'asc'; }
KW_DESC = 'desc'i !ident_start { return 'desc'; }
KW_USABLE = 'usable'i !ident_start { return 'usable'; }
KW_INVALIDATION = 'invalidation'i !ident_start { return 'invalidation'; }

KW_VARYING = 'varying'i !ident_start { return 'varying'; }
KW_VARCHAR = 'varchar'i !ident_start { return 'varchar'; }
Expand Down
41 changes: 41 additions & 0 deletions test/statements/create-index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const { Parser } = require("../../");

const parser = new Parser();

describe("create index statement", () => {
it("create unique index some_index on some_table (col1, col2);", () => {
const sql = "create unique index some_index on some_table (col1, col2);";
const ast = parser.parse(sql);
const expected = {
operation: "create",
type: "unique",
object: "index",
if_not_exists: null,
name: {
schema: null,
name: "some_index",
},
target: {
name: {
schema: null,
name: "some_table",
},
object: "table",
t_alias: null,
columns: [
{
name: "col1",
order: null,
},
{
name: "col2",
order: null,
},
],
},
usable: null,
invalidation: null,
};
expect(ast[0]).toMatchObject(expected);
});
});