DEFAULT now() in CREATE TABLE fails #10

Open
opened 2026-08-07 14:22:16 +00:00 by hum3 · 0 comments
Owner

Problem

DEFAULT now() in a column definition causes a SQLite syntax error:

CREATE TABLE t (
    created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- sqlite3: SQL logic error: near "(": syntax error

Workaround

Use DEFAULT CURRENT_TIMESTAMP instead (a keyword, not a function call):

CREATE TABLE t (
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

Expected

The DDL translator should rewrite DEFAULT now() to DEFAULT CURRENT_TIMESTAMP (or DEFAULT (datetime("now"))) so it works against SQLite, matching PostgreSQL behaviour where now() and CURRENT_TIMESTAMP are equivalent.


Migrated from Codeberg: originally #10, opened 2026-04-13.

## Problem `DEFAULT now()` in a column definition causes a SQLite syntax error: ```sql CREATE TABLE t ( created_at TIMESTAMPTZ NOT NULL DEFAULT now() ); -- sqlite3: SQL logic error: near "(": syntax error ``` ## Workaround Use `DEFAULT CURRENT_TIMESTAMP` instead (a keyword, not a function call): ```sql CREATE TABLE t ( created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); ``` ## Expected The DDL translator should rewrite `DEFAULT now()` to `DEFAULT CURRENT_TIMESTAMP` (or `DEFAULT (datetime("now"))`) so it works against SQLite, matching PostgreSQL behaviour where `now()` and `CURRENT_TIMESTAMP` are equivalent. --- *Migrated from Codeberg: originally [#10](https://codeberg.org/hum3/go-postgres/issues/10), opened 2026-04-13.*
Sign in to join this conversation.
No labels
OnDemand
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
hum3/go-postgres#10
No description provided.