Skip to content

Commit

Permalink
Merge pull request #1745 from taozhi8833998/fix-double-quoted-pg
Browse files Browse the repository at this point in the history
fix: as double quoted in pg
  • Loading branch information
taozhi8833998 authored Jan 4, 2024
2 parents 4f669df + fc01b37 commit 2610a42
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pegjs/postgresql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down
13 changes: 12 additions & 1 deletion test/postgres.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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.`)
})
})

})

0 comments on commit 2610a42

Please sign in to comment.