やったこと
Goのdatabase/sqlパッケージを使用し、DATE型のカラムtest_dayに日付をINSERTした。
query := INSERT INTO my_table(test_day) VALUES('1999-01-01')
db.ExecContext(ctx, query)
エラー
ORA-01861: literal does not match format string
対応
OracleDBのTO_DATE関数を使用する
明示的にDATE型に変換して日時データにする必要がある。
query := INSERT INTO my_table(test_day) VALUES(TO_DATE('1999-01-01','YYYY-MM-DD'))
db.ExecContext(ctx, query)
こちらでも可能だが、時刻の指定はできず、時刻は常に00時00分00秒となる
(日付リテラルであり、日時リテラルではない)
query := INSERT INTO my_table(test_day) VALUES(DATE '1999-01-01')
db.ExecContext(ctx, query)