Skip to content

Commit e5164f6

Browse files
committed
Support SET as column name (but not as implicit alias)
1 parent 4fd0b10 commit e5164f6

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/keywords/postgresql.keywords.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ export const postgresqlKeywords: Record<string, boolean> = {
178178
.filter(([_, def]) => def.reserved)
179179
.map(([kw]) => [kw, true])
180180
),
181-
// TODO: Temporarily including these actually non-reserved words
182-
SET: true,
183181
};
184182

185183
export const postgresqlRequiresAsKeywords: Record<string, boolean> = {
@@ -188,6 +186,19 @@ export const postgresqlRequiresAsKeywords: Record<string, boolean> = {
188186
.filter(([_, def]) => def.requiresAs || def.reserved)
189187
.map(([kw]) => [kw, true])
190188
),
191-
// TODO: Temporarily including these actually non-reserved words
189+
190+
// TODO: SET is non-reserved keyword in PostgreSQL
191+
// and it's also allowed as implicit alias,
192+
// but that causes a "conflict" in UPDATE ... SET statement.
193+
//
194+
// The following is allowed:
195+
// UPDATE foo SET set = 10;
196+
//
197+
// But the following is error:
198+
// UPDATE foo set SET x = 10;
199+
//
200+
// PostgreSQL parser pulls some magic to deal with this.
201+
// As only crazy people really need this, and most other dialects treat SET
202+
// as reserved keyword, we'll require AS for SET as a workaround for now.
192203
SET: true,
193204
};

test/select/select.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,19 @@ describe("select", () => {
114114
test("SELECT minute");
115115
test("SELECT second");
116116
});
117+
118+
it("supports SET as explicit alias", () => {
119+
test("SELECT 12 AS set");
120+
});
121+
122+
// Currently not supported, though actually PostgreSQL supports this.
123+
it.skip("supports SET as implicit alias", () => {
124+
test("SELECT 4 set");
125+
});
126+
127+
it("supports SET as column name", () => {
128+
test("SELECT set");
129+
});
117130
});
118131
});
119132

0 commit comments

Comments
 (0)