-
Notifications
You must be signed in to change notification settings - Fork 780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A syntax parsing error when executing SQL queries #1051
Comments
Thanks for this thorough repro and analysis @key7men! Will have to think a bit on how to address this. sql-limiter uses moo to parse SQL, but unfortunately lacks a means of handling dollar quoted strings. no-context/moo#132 Will have to give this some thought. Some ideas in mind:
|
For now, to solve this recognition problem, I added an extra judgment as a temporary solution async create(batch) {
let createdBatch;
const queryText = batch.selectedText || batch.batchText;
// sqlLimiter could fail at parsing the SQL text
// If this happens the error is captured and reported as if it were a query error
let error;
let statementTexts = [queryText];
try {
statementTexts = sqlLimiter
.getStatements(queryText)
.map((s) => sqlLimiter.removeTerminator(s))
.filter((s) => s && s.trim() !== '');
if (queryText.includes('$$')) {
statementTexts = assembleForPG(statementTexts);
}
} catch (e) {
error = e;
}
...
function assembleForPG(list) {
let tmp = '';
let result = [];
const len = list.length;
for (let i = 0; i < len; i++) {
if (list[i].indexOf('$$') !== -1) {
if (list[i].indexOf('$$') === list[i].lastIndexOf('$$')) {
if (tmp) {
tmp = tmp + list[i] + ';';
result.push(tmp);
tmp = '';
} else {
tmp = tmp + list[i] + ';';
}
}
} else if (tmp) {
tmp = tmp + list[i] + ';';
} else {
result.push(list[i]);
}
}
return result;
} Next I will try to optimize sql-limiter |
Sqlpad version:
6.6.0
Description:
problem snapshot:
reason:
The service program parses the SQL query statements entered by the user in the SQL editor. When I check the code in
server/model/batches.js
:I found the program to use sqlLimiter for determining how to parse out an independently executable SQL statement.
But, PostgreSQL uses specific syntax to embed multiple SQL statements within a single SQL statement to create stored procedures like the following (note the '$$' tag):
Please considering optimizing the sql-limiter parser.
The text was updated successfully, but these errors were encountered: