Filip van Hoft
Filip van Hoft

Reputation: 301

PostgreSQL heterogeneous insertion

I have list like ["0", "s", "a"] which is generated in process of evaluating , that list should be inserted in PostgreSQL with postgresql-simple where first column is bigint, but when I'm using

let vals = map evalVal field :: [String] 
execute conn query vals

I have error with wrong types conversion

Incompatible {errSQLType = "int4", errSQLTableOid = Just (Oid 25340),

How can I make library understand that first value is int?

Upvotes: 1

Views: 176

Answers (1)

Cactus
Cactus

Reputation: 27626

If you have three columns with types Int, String, String, then you can't represent a row of this schema with [String], you have to use (Int, String, String). If you change vals to this type, it should work.

Of course, this means your way of generating vals needs to change as well, since map evalVal fields only makes sense if the fields are all of the same type. But the details of this depend on what evalVal does.

Upvotes: 1

Related Questions