Skip to content

Commit d17386d

Browse files
committed
Also support LOGGED & UNLOGGED syntax for sequences
Refs #107
1 parent fa2c41a commit d17386d

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

src/cst/Sequence.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ export type SequenceOption =
4444
| SequenceOptionCycle
4545
| SequenceOptionNoCycle
4646
| SequenceOptionOwnedBy
47-
| SequenceOptionSequenceName;
47+
| SequenceOptionSequenceName
48+
| SequenceOptionLogged
49+
| SequenceOptionUnlogged;
4850

4951
export interface SequenceOptionAsType extends BaseNode {
5052
type: "sequence_option_as_type";
@@ -123,6 +125,16 @@ export interface SequenceOptionSequenceName extends BaseNode {
123125
name: EntityName;
124126
}
125127

128+
export interface SequenceOptionLogged extends BaseNode {
129+
type: "sequence_option_logged";
130+
loggedKw: Keyword<"LOGGED">;
131+
}
132+
133+
export interface SequenceOptionUnlogged extends BaseNode {
134+
type: "sequence_option_unlogged";
135+
unloggedKw: Keyword<"UNLOGGED">;
136+
}
137+
126138
export interface AlterSequenceStmt extends BaseNode {
127139
type: "alter_sequence_stmt";
128140
alterKw: Keyword<"ALTER">;

src/parser.pegjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4200,6 +4200,8 @@ sequence_option
42004200
/ sequence_option_no_cycle
42014201
/ sequence_option_owned_by
42024202
/ sequence_option_sequence_name
4203+
/ sequence_option_logged
4204+
/ sequence_option_unlogged
42034205

42044206
sequence_option_as_type
42054207
= kw:(AS __) type:data_type {
@@ -4283,6 +4285,16 @@ sequence_option_sequence_name
42834285
return loc({ type: "sequence_option_sequence_name", sequenceNameKw: read(kw), name });
42844286
}
42854287

4288+
sequence_option_logged
4289+
= kw:LOGGED {
4290+
return loc({ type: "sequence_option_logged", loggedKw: kw });
4291+
}
4292+
4293+
sequence_option_unlogged
4294+
= kw:UNLOGGED {
4295+
return loc({ type: "sequence_option_unlogged", unloggedKw: kw });
4296+
}
4297+
42864298
alter_sequence_stmt
42874299
= kw:(ALTER __)
42884300
sequenceKw:(SEQUENCE __)

src/showNode/sequence.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export const sequenceMap: FullTransformMap<string, AllSequenceNodes> = {
3131
sequence_option_owned_by: (node) => show([node.ownedByKw, node.owner]),
3232
sequence_option_sequence_name: (node) =>
3333
show([node.sequenceNameKw, node.name]),
34+
sequence_option_logged: (node) => show(node.loggedKw),
35+
sequence_option_unlogged: (node) => show(node.unloggedKw),
3436

3537
// ALTER SEQUENCE
3638
alter_sequence_stmt: (node) =>

test/ddl/alter_table.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,13 @@ describe("alter table", () => {
234234
"ALTER COLUMN foo ADD GENERATED ALWAYS AS IDENTITY (START WITH 10 INCREMENT BY 5)"
235235
);
236236
});
237-
// SEQUENCE NAME is not among the general sequence options
238-
it("supports ADD GENERATED .. AS IDENTITY (SEQUENCE NAME ...)", () => {
237+
// SEQUENCE NAME, LOGGED, UNLOGGED are not among the general sequence options
238+
it("supports ADD GENERATED .. AS IDENTITY (special options ...)", () => {
239239
testAlterWc(
240240
"ALTER COLUMN foo ADD GENERATED ALWAYS AS IDENTITY (SEQUENCE NAME my_seq START WITH 10)"
241241
);
242+
testAlterWc("ALTER COLUMN foo ADD GENERATED ALWAYS AS IDENTITY (LOGGED)");
243+
testAlterWc("ALTER COLUMN foo ADD GENERATED ALWAYS AS IDENTITY (UNLOGGED)");
242244
});
243245

244246
describe("alter identity column", () => {

test/ddl/constraints_column.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,11 @@ describe("column constraints", () => {
184184
testColConstWc("GENERATED ALWAYS AS IDENTITY (START WITH 10 INCREMENT BY 5)");
185185
});
186186

187-
// SEQUENCE NAME is not among the general sequence options
188-
it("GENERATED .. AS IDENTITY (SEQUENCE NAME ...)", () => {
187+
// SEQUENCE NAME, LOGGED, UNLOGGED are not among the general sequence options
188+
it("GENERATED .. AS IDENTITY (special options ...)", () => {
189189
testColConstWc("GENERATED ALWAYS AS IDENTITY (START WITH 10 SEQUENCE NAME schm.my_seq)");
190+
testColConstWc("GENERATED ALWAYS AS IDENTITY (LOGGED)");
191+
testColConstWc("GENERATED ALWAYS AS IDENTITY (UNLOGGED)");
190192
});
191193
});
192194
});

0 commit comments

Comments
 (0)