Comments (2)
Further research indicates to me that Clickhouse does not even support constraints with foreign keys. It does not seem to be supported in their SQL spec.
See:
https://clickhouse.com/docs/en/sql-reference/statements/alter/constraint
https://stackoverflow.com/questions/66354832/how-can-i-use-functionality-of-primary-key-and-foreign-key-in-clickhouse
Take for instance this table:
type User struct {
HModel
Email string `gorm:"index"`
Roles []*Role `gorm:"many2many:user_roles;"`
FirstName string
LastName string
Role string
}
...
type HModel struct {
ID string `gorm:"primarykey"`
CreatedAt time.Time
UpdatedAt time.Time
// DeletedAt DeletedAt `gorm:"index"`
}
When doing a err = db.AutoMigrate(&User{}, &Role{})
the driver will attempt this:
ALTER TABLE `user_roles` ADD CONSTRAINT `fk_user_roles_role`
FOREIGN KEY (`role_id`,`role_type`) REFERENCES `roles`(`id`,`type`)
But, at least based on my very limited (a week worth of messing with Clickhouse) this SQL statement is just wrong.
For instance running it in clickhouse-client results in:
Syntax error: failed at position 63 ('FOREIGN'):
ALTER TABLE `user_roles` ADD CONSTRAINT `fk_user_roles_role` FOREIGN KEY (`role_id`,`role_type`) REFERENCES `roles`(`id`,`type`)
Expected one of: CHECK, ASSUME
Maybe someone could shed light on this.
But - as far as i can tell - this driver is just basically broken.
from clickhouse.
I think the only reasonable way to do many-to-many in clickhouse would be to simply use the ReplacingMergeTree
engine using TUPLE()
as the ORDER BY
Anyone? thoughts?
Or please tell me I am missing something big here.
from clickhouse.
Related Issues (20)
- happen error in create. print error [unsupported data type: &[]] HOT 1
- QuoteTo function has bugs
- Automigration doesn't work with table on cluster mode HOT 2
- Does GORM with Clickhouse support Preload
- AutoMigrate can break clickhouse data if you change a column type
- SkipDefaultTransaction = true时,没有办法通过gorm提供的方法写入数据 HOT 3
- 神奇的字段,id,当我使用id作为字段名时,会出现在INSERT INTO时,两次赋值,导致message: Column id specified more than once
- Updates not working for array column
- go get -u gorm.io/driver/clickhouse 报错缺少依赖包 github.com/mitchellh/osext HOT 2
- how can gorm-clickhouse read "with totals" row ?
- OpenDB方法不存在 HOT 1
- sql: Scan error on column index 2, name "col3": unsupported Scan, storing driver.Value type []string into type *sql.RawBytes HOT 2
- setting allow_experimental_object_type to migrate JSON type fields to Clickhouse DB HOT 1
- 官方的可以,这个根本不行啊 HOT 1
- dsn clien question
- 当前的clickhouse驱动无法保证集群数据表的创建
- clickhouse多节点怎么连呀
- netip 是1.18的库 是必须把sdk版本升级到1.18吗 HOT 2
- Can't insert FixedString column using GORM serializer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clickhouse.