Search code examples
sqltypescriptsqlitenode-sqlite3

Why does my "Create Table" statement return "Near '(': syntax error"?


Error :

Near "(": syntax error

SQL statement :

CREATE TABLE IF NOT EXISTS tickets (
    numero INTEGER PRIMARY KEY AUTOINCREMENT,
    identifier VARCHAR(4) NOT NULL,
    subject VARCHAR(150) NOT NULL,
    concerned_staff TEXT NULL,
    author_id VARCHAR(22) NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT current_timestamp(),
    is_archived BOOLEAN NOT NULL DEFAULT false,
    ticket_channel_id VARCHAR(24) NOT NULL
);

I do not understand why. The only other question doesn't fit what I'm doing. My goal is to get a numeric value of the time. I don't want 21-12-2022 10:00:00 but 1671613200.


Solution

  • I do not understand why.

    Change current_timestamp() to CURRENT_TIMESTAMP.

    I don't want 21-12-2022 10:00:00 but 1671613200.

    created_at TIMESTAMP resolves to numeric affinity while CURRENT_TIMESTAMP returns string value. Use unixepoch() instead:

    created_at TIMESTAMP NOT NULL DEFAULT (unixepoch()),