diff --git a/pegjs/postgresql.pegjs b/pegjs/postgresql.pegjs index c5db0c2e..967d3644 100644 --- a/pegjs/postgresql.pegjs +++ b/pegjs/postgresql.pegjs @@ -2887,7 +2887,7 @@ value_alias_clause alias_clause = KW_AS __ i:alias_ident { /*=>alias_ident*/ return i; } - / KW_AS? __ i:ident { /*=>ident*/ return i; } + / KW_AS? __ i:alias_ident { /*=>alias_ident*/ return i; } into_clause = KW_INTO __ v:var_decl_list { @@ -4053,7 +4053,7 @@ alias_ident if (!c) return name; return `${name}(${c[3].join(', ')})` } - / name:quoted_ident { + / name:double_quoted_ident { // => IGNORE return name; } diff --git a/test/postgres.spec.js b/test/postgres.spec.js index 65138219..2de74a36 100644 --- a/test/postgres.spec.js +++ b/test/postgres.spec.js @@ -1358,6 +1358,13 @@ describe('Postgres', () => { 'CREATE TABLE "public"."authors_table" ("author_id" INTEGER NOT NULL, "first_name" CHARACTER VARYING NOT NULL, "last_name" CHARACTER VARYING NOT NULL, "birth_date" DATE)' ] }, + { + title: 'as double quoted', + sql: [ + 'select 1 as "one"', + 'SELECT 1 AS "one"' + ] + }, ] function neatlyNestTestedSQL(sqlList){ sqlList.forEach(sqlInfo => { @@ -1634,6 +1641,10 @@ describe('Postgres', () => { it('should proc assign', () => { expect(procToSQL({stmt: {type: 'assign', left: {type: 'default', value: 'abc'}, keyword: '', right: {type: 'number', value: 123}, symbol: '='}})).to.be.equal('abc = 123') }) + it('should throw error', () => { + const sql = "select 1 as 'one'" + const fun = parser.astify.bind(parser, sql, opt) + expect(fun).to.throw(`Expected "--", "/*", "\\"", [ \\t\\n\\r], or [A-Za-z_一-龥] but "'" found.`) + }) }) - })