0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SQlite3にてレコード作成日時のタイムスタンプ(ローカルタイム)設定でエラー

Last updated at Posted at 2020-02-09

はまったのでメモ
環境:Python 3.7.1
利用モジュール:sqlite3

レコード新規作成時にローカルタイムのタイムスタンプを自動で挿入するようにテーブル作成

create table user_data(
name text not null,
creation_datetime timestamp not null default datetime(current_timestamp,'localtime'))

上記のコードを実行。すると・・・
「sqlite3.OperationalError: near "(": syntax error」が発生。
「creation_datetime」カラムのdatetime関数を括弧で囲まないと文法エラーになるもよう。

create table user_data(
name text not null,
creation_datetime timestamp not null default (datetime(current_timestamp,'localtime')))

上記コードで正常にテーブルが作成されることを確認。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?