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.

Optional generated column for insert/update (default constraint)

See original GitHub issue

Use case: I have a field createdat which is auto generated. I’d expect it to maintain its value regardless of when I update it. Basically looking for a way to enforce a generated column to NOT update its value when an UPDATE command is issued.

Feature description:

Table schema

CREATE TABLE mytable(
    somefield STRING,
    createdat TIMESTAMP GENERATED ALWAYS AS CURRENT_TIMESTAMP(3)
)
INSERT INTO mytable (somefield) VALS ('some string')

'some string', 1517615548000
UPDATE mytable SET somefield = 'another string' WHERE somefield = 'some string'

'another string', 1517615548000

In the above example, it’d be great to persist the original value even if any of the other column values are updated.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
mfusseneggercommented, Feb 7, 2018

I guess to support this use case in a better way we’d have to implement the default constraint?

0reactions
mfusseneggercommented, Mar 2, 2020

We added support for DEFAULT in 4.0 (https://github.com/crate/crate/pull/8794)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Column INSERT/UPDATE Defaults — SQLAlchemy 1.4 ...
The Identity construct allows a Column to be declared as an identity column and rendered in DDL as “GENERATED { ALWAYS | BY...
Read more >
SQL DEFAULT Constraint to Insert Column with a Default ...
SQL Server creates a constraint with a system-generated unique name. Create the table using the below query: USE demodatabase go CREATE TABLE ...
Read more >
Column Insert/Update Defaults
A DDL-specified DEFAULT column value. DefaultClause is a FetchedValue that also generates a “DEFAULT” clause when “CREATE TABLE” is emitted.
Read more >
How to get EF 6 to handle DEFAULT CONSTRAINT on a ...
I have a simple table I created, just to test Entity Framework 6 (EF6) and its interaction with the columns SQL Server is...
Read more >
SA0249 : Specify default value for columns added with NOT ...
Specify default value for the column added with NOT NULL constraint. Scope. The rule has a Batch scope and is applied only on...
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