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

Deparse bug:The table is wrapped in quotes, and the primary key is automatically unquoted #88

Closed
Hanko2024 opened this issue Jun 9, 2023 · 3 comments

Comments

@Hanko2024
Copy link

if true {
	sql := `ALTER TABLE ONLY public."Test1我们123@#$%"
	ADD CONSTRAINT "Test1我们123@#$%_pkey" PRIMARY KEY (c1);`
	result, err := pg_query.Parse(sql)
	if err != nil {
		fmt.Println("Parse err ", err)
		return
	}

	for _, rawStmt := range result.Stmts {
		var (
			tree = &pg_query.ParseResult{
				Version: result.Version,
				Stmts:   []*pg_query.RawStmt{rawStmt},
			}
		)

		stmt, err := pg_query.Deparse(tree)
		if err != nil {
			fmt.Println("Deparse err ", err)
			return
		}
		fmt.Printf("newSQL: %s\n", stmt)
	}
}

output:
newSQL: ALTER TABLE ONLY public."Test1我们123@#$%" ADD CONSTRAINT Test1我们123@#$%_pkey PRIMARY KEY (c1)

env go:
go 1.19
require github.com/pganalyze/pg_query_go/v4 v4.2.1

@Hanko2024
Copy link
Author

The execution of the primary key without quotation marks fails, so the table name cannot be case-sensitive or contain special characters

@lfittl
Copy link
Member

lfittl commented Jun 10, 2023

@liuhangyu Thanks for the report, this is indeed a bug - I've opened a fix in the underlying C library: pganalyze/libpg_query#195 (once that is merged it will be included when a new release of libpg_query is made, and the Go library is updated)

@Hanko2024
Copy link
Author

thanks for the reply

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

No branches or pull requests

2 participants