Skip to content
Open
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
8 changes: 4 additions & 4 deletions pegjs/postgresql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -4505,8 +4505,8 @@ regex_op
= "!~*" / "~*" / "~" / "!~"

regex_op_right
= op:regex_op __ right:(literal / comparison_expr) {
// => { op: regex_op; right: literal | comparison_expr}
= op:regex_op __ right:(additive_expr / literal / comparison_expr) {
// => { op: regex_op; right: additive_expr | literal | comparison_expr}
return { op: op, right: right };
}

Expand All @@ -4524,8 +4524,8 @@ in_op
/ KW_IN

like_op_right
= op:like_op __ right:(literal / comparison_expr) __ es:escape_op? {
// => { op: like_op; right: (literal | comparison_expr) & { escape?: escape_op }; }
= op:like_op __ right:(additive_expr / literal / comparison_expr) __ es:escape_op? {
// => { op: like_op; right: (additive_expr | literal | comparison_expr) & { escape?: escape_op }; }
if (es) right.escape = es
return { op: op, right: right };
}
Expand Down
35 changes: 35 additions & 0 deletions test/postgres.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,41 @@ describe('Postgres', () => {
'CREATE TABLE "test_table" (id INT NOT NULL, vector TSVECTOR)'
]
},
{
title: 'LIKE with string concatenation starting with a literal',
sql: [
`SELECT * FROM "MES-TimeStamps" WHERE "Task" LIKE '%' || 'step' || '%'`,
`SELECT * FROM "MES-TimeStamps" WHERE "Task" LIKE '%' || 'step' || '%'`
]
},
{
title: 'LIKE with string concatenation starting with a column',
sql: [
`SELECT * FROM "t" WHERE "Task" LIKE prefix || '%'`,
`SELECT * FROM "t" WHERE "Task" LIKE prefix || '%'`
]
},
{
title: 'NOT LIKE with string concatenation',
sql: [
`SELECT * FROM "t" WHERE "Task" NOT LIKE '%' || 'x'`,
`SELECT * FROM "t" WHERE "Task" NOT LIKE '%' || 'x'`
]
},
{
title: 'LIKE concatenation with ESCAPE clause',
sql: [
`SELECT * FROM "t" WHERE "Task" LIKE '%' || 'x' || '%' ESCAPE '!'`,
`SELECT * FROM "t" WHERE "Task" LIKE '%' || 'x' || '%' ESCAPE '!'`
]
},
{
title: 'regex match with string concatenation starting with a literal',
sql: [
`SELECT * FROM "t" WHERE "Task" ~ '^' || 'abc'`,
`SELECT * FROM "t" WHERE "Task" ~ '^' || 'abc'`
]
},
]
function neatlyNestTestedSQL(sqlList){
sqlList.forEach(sqlInfo => {
Expand Down