Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

i hope someone could help me with this,

So i'm building database backed website with clojure and postgresql, but i keep getting error. Here are the code and error on 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

here goes the code that caused error :

(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)

and

(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)

and

(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)

and

(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)

and

(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)

Any suggestion? Thank you in advance

edit schema for table 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")
)
share|improve this question
    
What's the schema for the user123 table? – schaueho Jun 17 '15 at 6:04
    
@schaueho 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") ) – dImas Angga Saputra Jun 17 '15 at 6:06
    
Your attempts look reasonable to me, the only thing that comes to my head is that maybe the "user-id" column name might cause some confusion. Have you tried with a different value than "user" for the username parameter to rule out that it's not barfing on the "user-id"? Otherwise, try specifying the loglevel property of the postgresql driver, maybe this will give you more information. See the documentation on sql/get-connection, this should be possible with the DriverManager approach. – schaueho Jun 17 '15 at 6:42
1  
i'm no database expert, but it appears to me that you are specifying username as an array of variable (but bounded) length strings - you probably, unless you are intending to have several user names per row, do not mean this. i would drop the [] from the definition and try again. same with password. – peter Jun 17 '15 at 8:15

Use (sql/execute! db1 ["INSERT INTO user123 VALUES (?, ?, ?)" "user" "pass" 1]) for your purpose

share|improve this answer
(sql/execute! db1 ["INSERT INTO user123 VALUES ({'user'}, {'pass'}, 1);"])
share|improve this answer

I think your should change :username to :user in your db specification.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.