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.

Table Editor doesn't allow default values like `CURRENT_DATE`

See original GitHub issue

Bug report

Describe the bug

The Table Editor in Studio doesn’t allow default values like CURRENT_DATE. However, it works as expected when done via SQL (both creating and altering a table).

To Reproduce

  1. Create a new table:
CREATE TABLE testdate (
    id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    date DATE NOT NULL
);
  1. Go to Table Editor and add default value CURRENT_DATE to column date.

This results in the notification: Failed to update column “date”: failed to update pg.columns with the given ID: invalid input syntax for type date: “CURRENT_DATE”

Expected behavior

When using SQL directly, you can set the default value and it works as expected:

ALTER TABLE testdate ALTER COLUMN date SET DEFAULT CURRENT_DATE;

I expect that the Table Editor supports values like CURRENT_DATE. (I have not tested CURRENT_TIME and similar, but expect the same behavior)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
soedirgocommented, Sep 27, 2022

This is one of the cases where defaultValueFormat needs to be "expression" I think - otherwise "CURRENT_DATE" will be treated (and escaped) as a string literal.

1reaction
joshenlimcommented, Sep 29, 2022

basically treat it as expression

hmm but this wouldn’t be right on the UI. esp if a user saved their default value as a literal, and they open the editor again and it shows that Is a SQL expression is toggled true

Read more comments on GitHub >

github_iconTop Results From Across the Web

Default value = today's date in MSDE table editor - MSDN - Microsoft
What do I put in the Default value of a DateTime field if I'm using the table editor for a MSDE table and...
Read more >
27645: Datetime field does not accept default NOW()
This means, for example, that you cannot set the default for a date column to be the value of a function such as...
Read more >
Setting default value for DATE type column to current ...
I have tried: ALTER TABLE `accounting` ALTER `accounting_date` SET DEFAULT CURRENT_DATE; ALTER TABLE `accounting` CHANGE `accounting_date` ` ...
Read more >
Changing a Column's Default Value - MySQL Cookbook by
To change a default value, use ALTER col_name SET DEFAULT : ALTER TABLE mytbl ALTER j SET DEFAULT 1000; Default values must be...
Read more >
SQL DEFAULT Constraint
The DEFAULT constraint is used to set a default value for a column. The default value will be added to all new records,...
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