Skip to content
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

Allow SQL statements to be terminated by semicolon #18472

Open
aalbu opened this issue Jul 31, 2023 · 2 comments
Open

Allow SQL statements to be terminated by semicolon #18472

aalbu opened this issue Jul 31, 2023 · 2 comments
Assignees

Comments

@aalbu
Copy link
Member

aalbu commented Jul 31, 2023

Several tools generate SQL statements that end with a semicolon. This is supported by most database systems out there. Wikipedia states:

SQL statements also include the semicolon (";") statement terminator. Though not required on every platform, it is defined as a standard part of the SQL grammar.

I have not been able to confirm that from the spec, but this has been mentioned in previous conversations in the community.

Note that this is simply a proposal to allow semicolon as a SQL statement terminator and not to support the submission of multiple statements separated by semicolon.

@findepi
Copy link
Member

findepi commented Aug 18, 2023

Indeed e.g. MySQL accepts any number of trailing semicolons, but rejects any subsequent queries.

PostgreSQL even allows multiple queries. Besides SQL injection, I don't know where this is useful

Class.forName("org.postgresql.Driver");
try (Connection connection = DriverManager.getConnection("jdbc:postgresql:https://localhost:15432/test", "test", "test");
        PreparedStatement stmt = connection.prepareStatement("SELECT 1;;SELECT 2")) {
    stmt.execute();
    System.out.println("first result set");
    stmt.getResultSet().close();
    System.out.println("second result set");
    System.out.println("getMoreResults = " + stmt.getMoreResults());
    stmt.getResultSet().close();
    System.out.println("getMoreResults = " + stmt.getMoreResults());
}

prints

first result set
second result set
getMoreResults = true
getMoreResults = false

@martint
Copy link
Member

martint commented Jun 21, 2024

This is consistent with the SQL specification. In fact, the semicolon is actually required in the spec:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants