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

Got panic: "block cannot be sorted - missing columns in requested order" when a column identifiers with double quotes #1216

Closed
YenchangChan opened this issue Mar 3, 2024 · 0 comments · Fixed by #1217
Labels

Comments

@YenchangChan
Copy link
Contributor

Describe the bug

I define a table with fields that have double quotes, and when I insert a record, I get an error using backticks. This bug was introduced in clickhouse-go 2.14.3 which introduced in the PR #1083, and has not been fixed so far. While it's not a good idea to define fields this way, I'm having this issue in production and hope it can be fixed.

Code example

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/ClickHouse/clickhouse-go/v2"
)

func main() {
	conn, err := clickhouse.Open(&clickhouse.Options{
		Addr: []string{"127.0.0.1:9000"},
	})
	if err != nil {
		log.Fatal(err)
	}

	ctx := context.Background()
        _ = conn.Exec(ctx, "DROP TABLE IF EXISTS example SYNC")
	createSql := "CREATE TABLE IF NOT EXISTS example (`@id` String,`\"@id_with_quotes\"` String) Engine = Memory"
	err = conn.Exec(ctx, createSql)
	if err != nil {
		log.Fatal(err)
	}

	_, err = conn.PrepareBatch(ctx, "INSERT INTO example (`@id`, `\"@id_with_quotes\"`)")
	if err != nil {
		log.Fatal(err)
	}
}

Error log

2024/03/03 09:13:42 block cannot be sorted - missing columns in requested order: ["@id_with_quotes"]
exit status 1

Configuration

Environment

  • Client version: 22.8.8.3
  • Language version: clickhouse-go2.14.3+
  • OS: CentOS 7 x86_64
  • Interface: ClickHouse API / database/sql compatible driver

ClickHouse server

  • ClickHouse Server version:
  • ClickHouse Server non-default settings, if any:
  • CREATE TABLE statements for tables involved:
  • Sample data for all these tables, use clickhouse-obfuscator if necessary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant