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

Parser Error: syntax error at or near "COMMENT" #3

Open
xmapst opened this issue Jan 2, 2025 · 3 comments
Open

Parser Error: syntax error at or near "COMMENT" #3

xmapst opened this issue Jan 2, 2025 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@xmapst
Copy link

xmapst commented Jan 2, 2025

2025-01-02T12:01:40.269+0800 Info [[email protected]/callbacks.go:134] github.com/alifiroozi80/[email protected]/migrator.go:199 Parser Error: syntax error at or near "COMMENT"
[99.599ms] [rows:0] CREATE TABLE t_task (id bigint COMMENT "ID" DEFAULT nextval('t_task'),created_at timestamptz COMMENT "创建时间",updated_at timestamptz COMMENT "更新时间",name varchar(256) NOT NULL COMMENT "名称",desc text CO
MMENT "描述",node varchar(256) DEFAULT null COMMENT "节点",async boolean NOT NULL DEFAULT false COMMENT "异步",timeout bigint NOT NULL DEFAULT 86400000000000 COMMENT "超时时间",disable boolean NOT NULL DEFAULT false COMMENT "禁 用",message text COMMENT "消息",state bigint NOT NULL DEFAULT 0 COMMENT "状态",old_state bigint NOT NULL DEFAULT 0 COMMENT "旧状态",s_time timestamptz COMMENT "开始时间",e_time timestamptz COMMENT "结束时间",PRIMARY KEY (id))
@alifiroozi80
Copy link
Owner

Hey @xmapst
Thanks for trying the driver.
A couple of things you should know:

  1. Commenting a column during the build is not possible in DuckDB. For more info, check the DuckDB documentation.
  2. Only after creating can you comment on existing columns with a COMMENT ON statement.
  3. The COMMENT ON statement currently has the following limitations:
  • It is not possible to comment on schemas or databases.
  • It is impossible to comment on things with a dependency (e.g., a table with an index).
  1. You can see this from one of the GORM maintainers: I think only the MySQL driver supports this at the moment.

All that being said, it can be added to this DuckDB driver. I will add the steps here for you or anyone who wants to contribute to the driver (I will add it eventually myself):

During opening the connection, we can pass some variables to duckdb.Config{} to enable comments.
Then behind the sense, when the user enables this, when we create a table in CreateTable function, we also call another function after creation that uses COMMENT ON statement and comment all the columns.

@alifiroozi80 alifiroozi80 self-assigned this Jan 2, 2025
@alifiroozi80 alifiroozi80 added the enhancement New feature or request label Jan 2, 2025
@xmapst
Copy link
Author

xmapst commented Jan 2, 2025

github.com/alifiroozi80/[email protected]/migrator.go:199 Parser Error: syntax error at or near "desc"
[95.551ms] [rows:0] CREATE TABLE t_task (id bigint DEFAULT nextval('t_task'),created_at timestamptz,updated_at timestamptz,name varchar(256) NOT NULL,desc varchar(256),node varchar(256) DEFAULT null,async boolean NOT NULL DEFAUL
T false,timeout bigint NOT NULL DEFAULT 86400000000000,disable boolean NOT NULL DEFAULT false,message text,state bigint NOT NULL DEFAULT 0,old_state bigint NOT NULL DEFAULT 0,s_time timestamptz,e_time timestamptz,PRIMARY KEY (id))

@alifiroozi80
Copy link
Owner

Please open a new issue for any issue, and let's keep every issue clean and relevant. However, I will answer that here.

The desc keyword is reserved in many SQL dialects, including DuckDB. It is commonly used in ORDER BY clauses to indicate descending order, e.g., ORDER BY column_name DESC.

Since desc is a reserved keyword, it cannot be used as an identifier (like a column name) unless you escape it. You can escape it by enclosing it in double quotes, like "desc". However, a better practice is avoiding using reserved keywords as identifiers to maintain compatibility and readability across databases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants