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
Support default expression value of another field in a table #1618
Comments
You should be able to do that using You didn't post your table definition, but I would expect that something like object EntryTable : UUIDTable() {
val entryId = uuid("entry_id").defaultExpression(EntryTable.id)
} would work. |
I'm using an UUIDTable:
Both of these errors are displayed at the same time in the IDE |
You're right, it won't work for PKs, since Probably having a custom expression is the way to go: object EntryTable : UUIDTable() {
val entryId = uuid("entry_id").defaultExpression(object : Expression<UUID>() {
override fun toQueryBuilder(queryBuilder: QueryBuilder) = queryBuilder {
append("ID")
}
})
} This generates the following SQL: CREATE TABLE IF NOT EXISTS entry (id uuid PRIMARY KEY, entry_id uuid DEFAULT (ID) NOT NULL) By the way, I'm curious, which database are you using? |
Yeah I said that this won't work with sql, but I wanted to do this in runtime then. Wouldn't it be possible? |
There's To reference ID of a newly created row, you need to somehow obtain it first. Currently the default values are set independently from one another: Exposed/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/InsertStatement.kt Line 95 in 9c0d295
And I don't see any guarantees that your EntityID default value will be initialized first. |
Okay, I just settled on treating this functionality as impossible to implement using neither sql or orms of any kind. We can close this if we mention that this is not supported somewhere in the docs |
I want to match exposed schema declaration to the following sql:
(this won't work with raw sql but is this possible with exposed?)
But how can I do this using exposed syntax, except for defining my own custom expression?
I couldn't find ways to convert column to Expression, couldn't do it using CustomFunction, haven't found any other ways
The text was updated successfully, but these errors were encountered: