|
11 | 11 |
|
12 | 12 | import net.sf.jsqlparser.JSQLParserException; |
13 | 13 | import net.sf.jsqlparser.expression.JsonExpression; |
| 14 | +import net.sf.jsqlparser.parser.CCJSqlParserUtil; |
| 15 | +import net.sf.jsqlparser.schema.Column; |
| 16 | +import net.sf.jsqlparser.statement.Statements; |
| 17 | +import net.sf.jsqlparser.statement.insert.Insert; |
14 | 18 | import net.sf.jsqlparser.test.TestUtils; |
15 | 19 | import org.junit.jupiter.api.Assertions; |
16 | 20 | import org.junit.jupiter.api.Test; |
17 | 21 |
|
| 22 | +import java.util.List; |
| 23 | + |
18 | 24 | import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; |
19 | 25 |
|
20 | 26 | public class PostgresTest { |
@@ -62,4 +68,31 @@ public void testJSonOperatorIssue1571() throws JSQLParserException { |
62 | 68 | "select visit_hour,json_array_elements(into_sex_json)->>'name',json_array_elements(into_sex_json)->>'value' from period_market"; |
63 | 69 | TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true); |
64 | 70 | } |
| 71 | + |
| 72 | + @Test |
| 73 | + void testPostgresQuotingIssue1335() throws JSQLParserException { |
| 74 | + String sqlStr = |
| 75 | + "INSERT INTO \"table\"\"with\"\"quotes\" (\"column\"\"with\"\"quotes\")\n" |
| 76 | + + "VALUES ('1'), ('2'), ('3');\n" |
| 77 | + + "\n" |
| 78 | + + "UPDATE \"table\"\"with\"\"quotes\" SET \"column\"\"with\"\"quotes\" = '1.0' \n" |
| 79 | + + "WHERE \"column\"\"with\"\"quotes\" = '1';\n" |
| 80 | + + "\n" |
| 81 | + + "SELECT \"column\"\"with\"\"quotes\" FROM \"table\"\"with\"\"quotes\"\n" |
| 82 | + + "WHERE \"column\"\"with\"\"quotes\" IS NOT NULL;"; |
| 83 | + |
| 84 | + Statements statements = CCJSqlParserUtil.parseStatements(sqlStr); |
| 85 | + Assertions.assertEquals(3, statements.size()); |
| 86 | + |
| 87 | + Insert insert = statements.get(Insert.class, 0); |
| 88 | + Assertions.assertEquals( |
| 89 | + "\"table\"\"with\"\"quotes\"", insert.getTable().getFullyQualifiedName()); |
| 90 | + |
| 91 | + PlainSelect select = statements.get(PlainSelect.class, 2); |
| 92 | + List<SelectItem<?>> selectItems = select.getSelectItems(); |
| 93 | + |
| 94 | + Assertions.assertEquals( |
| 95 | + "\"column\"\"with\"\"quotes\"", |
| 96 | + selectItems.get(0).getExpression(Column.class).getColumnName()); |
| 97 | + } |
65 | 98 | } |
0 commit comments