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

Document supported SQL comment prefixes #38385

Closed
wants to merge 1 commit into from

Conversation

PENEKhun
Copy link
Contributor

Situation

I am attempting to initialize a database following the instructions in the Spring Boot documentation under the "Initialize a Database Using Basic SQL Scripts" section.

When initializing the database with SQL files using sql.init.mode=always, you can specify the SQL file for initialization in the /resources directory (e.g., /resources/schema.sql).

Below is the content of the /resources/schema.sql file for initializing the schema:

# 1. remove table start
drop table if exists firstTable;
drop table if exists secondTable;
# 1. remove table end

# 2. create table start
create table firstTable
(
    id                   bigint auto_increment
        primary key,
    test_field           bigint               not null
);

create table secondTable
(
    id                   bigint auto_increment
        primary key,
    test_field           bigint               not null
);
# 2. create table end

In schema.sql, '#' is used for inline comments. However, since the DEFAULT_COMMENT_PREFIX is '--', some SQL statements were not parsed correctly, leading to issues as shown in the following image:

Parsing Issue

As a result, the table creation for firstTable, as specified in schema.sql, was ignored:

Table Creation Ignored

To avoid any potential misunderstanding, I suggest adding a mention of this issue in the documentation.

Changes

Added the following statement to [[howto.data-initialization.using-basic-sql-scripts]]

NOTE: When including comments in your SQL file, it is advisable to use -- for single-line comments and /* and */ for block comments. Be cautious when using other comment formats, as they may lead to the omission of certain SQL statements during parsing.

Refine the note about SQL comments in the documentation for initializing a database using basic SQL scripts in Spring Boot. The revised statement provides clearer guidance on using `--` for single-line comments and `/*` and `*/` for block comments, with a caution about potential issues with other comment formats.
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 17, 2023
@PENEKhun PENEKhun changed the title Add howto guidance on comments in sql for Database Initialization. Improve howto guidance on comments in sql for Database Initialization. Nov 17, 2023
@mhalbritter
Copy link
Contributor

mhalbritter commented Nov 22, 2023

Hello! Which SQL dialect are you using that # starts a comment? I've only encountered SQL comments with -- so far.

@mhalbritter mhalbritter added the status: waiting-for-feedback We need additional information before we can continue label Nov 22, 2023
@PENEKhun
Copy link
Contributor Author

@mhalbritter

mysql and mariadb support # comments.
Please refer to the following official references

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 22, 2023
@mhalbritter
Copy link
Contributor

mhalbritter commented Nov 22, 2023

I wonder if we should make the comment settings configurable so that you can continue to use # for comments. Let's see what the rest of the team thinks.

@mhalbritter mhalbritter added for: team-attention An issue we'd like other members of the team to review and removed for: team-attention An issue we'd like other members of the team to review labels Nov 22, 2023
@mhalbritter
Copy link
Contributor

Ah, never mind, i found an old discussion about that: #16820

@mhalbritter mhalbritter added this to the 2.7.x milestone Nov 22, 2023
@mhalbritter mhalbritter added type: documentation A documentation update and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Nov 22, 2023
@mhalbritter mhalbritter self-assigned this Nov 22, 2023
@mhalbritter mhalbritter changed the title Improve howto guidance on comments in sql for Database Initialization. Document support SQL comment prefixes Nov 22, 2023
@mhalbritter mhalbritter changed the title Document support SQL comment prefixes Document supported SQL comment prefixes Nov 22, 2023
@mhalbritter
Copy link
Contributor

Thank you very much and congratulations on your first contribution 🎉!

@mhalbritter mhalbritter modified the milestones: 2.7.x, 2.7.18 Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants