我希望有人可以帮助我,
所以我正在使用clojure和postgresql构建数据库支持的网站, 但我一直在收到错误。 以下是REPL的代码和错误:
(ns app.config-postgre
(require [clojure.java.jdbc :as sql]))
(def db1
{:classname "org.postgresql.Driver"
:subprotocol "postgresql"
:subname "//localhost:5432/dbname"
:username "username"
:password "password})
;;that's not the real username and password, the real one is right
这里是导致错误的代码:
(sql/insert! db1 :user123
{:username "user" :password "pass" :user-id "1"})
;;PSQLException ERROR: syntax error at or near "user"
Position: 43 org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse (QueryExecutorImpl.java:2157)
和
(sql/execute! db1 ["INSERT INTO user123 VALUES ('{\"user\", \"pass\" ,1}')"])
;;PSQLException ERROR: null value in column "password" violates not-null constraint
Detail: Failing row contains ({user,pass,1}, null, null). org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse (QueryExecutorImpl.java:2157)
和
(sql/execute! db1 ["INSERT INTO user123 VALUES ('{\"user\"},{\"pass\"},{1}')"])
;;PSQLException ERROR: malformed array literal: "{"user"},{"pass"},{1}"
Detail: Junk after closing right brace.
Position: 29 org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse (QueryExecutorImpl.java:2157)
和
(sql/execute! db1 ["INSERT INTO user123 VALUES ('\"user\",\"pass\",1')"])
;;PSQLException ERROR: malformed array literal: ""user","pass",1"
Detail: Array value must start with "{" or dimension information.
Position: 29 org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse (QueryExecutorImpl.java:2157)
和
(sql/execute! db1 ["INSERT INTO user123 VALUES ('user','pass',1)"])
;;PSQLException ERROR: malformed array literal: "user"
Detail: Array value must start with "{" or dimension information.
Position: 29 org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse (QueryExecutorImpl.java:2157)
有什么建议吗? 提前谢谢
编辑表user123的模式:
CREATE TABLE user123
(
username character varying(100)[] NOT NULL,
password character varying(100)[] NOT NULL,
"user-id" integer NOT NULL,
CONSTRAINT user_pkey PRIMARY KEY ("user-id")
)
答案 0 :(得分:1)
将(sql/execute! db1 ["INSERT INTO user123 VALUES (?, ?, ?)" "user" "pass" 1])
用于您的目的
答案 1 :(得分:0)
(sql/execute! db1 ["INSERT INTO user123 VALUES ({'user'}, {'pass'}, 1);"])
答案 2 :(得分:0)
我认为您应该在数据库规范中将:用户名更改为:用户。