Skip to content

Fix line comment check: Do not skip comment includes multi-line SQL#1121

Merged
gfx merged 1 commit intosqldef:masterfrom
winebarrel:fix_line_comment_skip
Feb 4, 2026
Merged

Fix line comment check: Do not skip comment includes multi-line SQL#1121
gfx merged 1 commit intosqldef:masterfrom
winebarrel:fix_line_comment_skip

Conversation

@winebarrel
Copy link
Contributor

@winebarrel winebarrel commented Feb 3, 2026

pgquery parser parses the following CREATE TABLE as -- comment\ncreate table ..., but it is treated as a line comment and skipped.

Fixed line comments not to be skipped if they contain \n.

-- comment
create table my_schema.foo (id int);
create index idx_foo_id on my_schema.foo (id);
$ psqldef --version
3.9.5 (cbca1fd)

$ psql -h localhost -U postgres
postgres=# create schema my_schema;
CREATE SCHEMA

$ cat test.sql
-- comment
create table my_schema.foo (id int);
create index idx_foo_id on my_schema.foo (id);

$ export PSQLDEF_PARSER=pgquery
$ cat test.sql | psqldef  -h localhost -U postgres postgres
-- Apply --
BEGIN;
-- comment
create table my_schema.foo (id int);
create index idx_foo_id on my_schema.foo (id);
ROLLBACK;
2026/02/03 17:47:02 pq: relation "my_schema.foo" does not exist (42P01)

@codecov
Copy link

codecov bot commented Feb 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
database/database.go 34.83% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@winebarrel winebarrel changed the title Fix line comment check: Do not skip multi-line SQL Fix line comment check: Do not skip comment includes multi-line SQL Feb 3, 2026
@gfx gfx added this pull request to the merge queue Feb 4, 2026
Merged via the queue into sqldef:master with commit cfb25ba Feb 4, 2026
25 checks passed
@sqldef-bot sqldef-bot bot mentioned this pull request Feb 4, 2026
logger.Printf("%s;\n", ddl)
// Skip ddlSuffix and execution for commented DDLs (e.g., "-- Skipped: ...")
if !strings.HasPrefix(ddl, "-- ") {
if !strings.HasPrefix(ddl, "-- ") && !strings.Contains(strings.TrimSpace(ddl), "\n") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if !strings.HasPrefix(ddl, "-- ") && !strings.Contains(strings.TrimSpace(ddl), "\n") {
if !(strings.HasPrefix(ddl, "-- ") && !strings.Contains(strings.TrimSpace(ddl), "\n")) {

@winebarrel winebarrel deleted the fix_line_comment_skip branch February 6, 2026 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants