question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support default expression value of another field in a table

See original GitHub issue

I want to match exposed schema declaration to the following sql:

alter table entry
add column entry_id uuid not null default (id); 
-- entry has a field named id

(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

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Nek-12commented, Dec 3, 2022

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

0reactions
AlexeySoshincommented, Oct 30, 2022

There’s clientDefault in Exposed that could work theoretically, but I don’t think would work practically.

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: https://github.com/JetBrains/Exposed/blob/9c0d2955424e3521abe025dcbdb932544aa8f3f1/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/InsertStatement.kt#L95

And I don’t see any guarantees that your EntityID default value will be initialized first.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set default values for fields or controls - Microsoft Support
This article explains how to set a default value for a table field or for a control on a form in an Access...
Read more >
Get Default Values For Fields from a Table in your ... - YouTube
In this video, I'm going to show you how to create a System Defaults table that you can use to provide default values...
Read more >
Set a Field's Default Value in an MS Access Table –
A default value is automatically entered in a field for a new record. You can set a default value for table fields set...
Read more >
Derive a Table Column's Default Value from another ... - Vertica
When you set a default value, Vertica evaluates the DEFAULT expression and sets the column on load operations, if the operation omits a...
Read more >
sql - Add a column to a table with a default value equal to the ...
..yes, but this will work for the existing rows only. It will not set the [newcolumn] value when new rows are inserted. You...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found