[英]HugSQL Error: column “date_answer” is of type date but expression is of type character varying?
I am using clojure hugSQL
to insert data into PostgreSQL
database.我正在使用clojure hugSQL
将数据插入PostgreSQL
数据库。 I am trying to insert multiple rows into an answer table using: tuple
* parameter.我正在尝试使用以下方法将多行插入答案表: tuple
* 参数。 When passing a date I get the following error:传递日期时出现以下错误:
Error: column "date_answer" is of type date but expression is of type character varying?
The sample SQL query created by HugSQL: HugSQL 创建的示例 SQL 查询:
INSERT INTO answer (a, b, c, d, date_answer) VALUES (62,76,NULL,NULL,'2020-05-13')
The same query works fine when inserted using terminal, so the format of a string seems to be fine.使用终端插入时,相同的查询可以正常工作,因此字符串的格式似乎很好。 Is there any way to specify individual fields inside the:tuple* parameter so that I can do something like:date_answer::date有什么方法可以在 :tuple* 参数中指定单个字段,以便我可以执行类似的操作:date_answer::date
This is my HugSQL query:这是我的 HugSQL 查询:
INSERT INTO answer (a, b, c, d, date_answer) VALUES:tuple*:answers插入答案 (a, b, c, d, date_answer) VALUES:tuple*:answers
You have to parse the value passed to a date.您必须解析传递给日期的值。 Eg,例如,
(ns your-ns
...
(:import
(java.time LocalDate)
(java.time.format DateTimeFormatter DateTimeParseException)))
(def ^:private yyyy-MM-dd-formatter
(DateTimeFormatter/ofPattern "yyyy-MM-dd"))
;; Assuming your HugSQL function is called insert
(insert {:answers [[a b c d (LocalDate/parse date-answer yyyy-MM-dd-formatter)]]
Then your date-answer is of type "date", and not of "character varying".那么您的日期答案是“日期”类型,而不是“字符变化”类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.