Persist-Postgresql assumes in insertSql' fixed column "id" #102

koeppl opened this Issue Nov 19, 2012 · 5 comments


None yet
2 participants

koeppl commented Nov 19, 2012

The instertSql' function in persistent's postgres-1.0.0-plugin does not count in different names for primary keys, as the line ") RETURNING id" is hardcoded.
Renaming the primary key of a table like "Book id=foo_id" in the models file results in a SQL-exception when invoking the "insert" function.
Book id=foo_id sql=books
name Text sql=book_name
language TatoebaLanguage sql=book_language
timestamp UTCTime default=CURRENT_TIMESTAMP sql=book_timestamp
UniqueName name
deriving Show

entryId <- runDB $ insert book

I'm using postgres 9.2.1, yesod-platform 1.1.2, persistent-postgresql 1.0.0


snoyberg commented Nov 20, 2012

Good catch. I've pushed a commit to resolve this. Can you test (you'll need to build the newer versions of both persistent and persistent-postgresql)?


koeppl commented Dec 8, 2012

Excellent solution, works now as expected.

@koeppl koeppl closed this Dec 8, 2012

koeppl commented Jan 5, 2013

I've spotted the same behaviour with the update function under persistent-postgresql- as I'm still sticking to "foo_id" instead of "id" for my primary key name.
So invoking

runDB $ update bookId [BookName =. "foo"]


[Debug#SQL] "UPDATE \"books\" SET \"book_name\"=? WHERE id=?" [PersistText "foo", PersistInt64 4245] @(persistent- ./Database/Persist/GenericSql/Raw.hs:130:5)
05/Jan/2013:17:55:45 +0100 [Error#yesod-core] SqlError {sqlState = "42703", sqlNativeError = 7, sqlErrorMsg = "execute: PGRES_FATAL_ERROR: ERROR:  column \"id\" does not exist\nLINE 1:

Interestingly, replace works.

@koeppl koeppl reopened this Jan 5, 2013


snoyberg commented Jan 6, 2013

Can you try the newest code on master?

koeppl commented Jan 6, 2013

Thanks, problem solved.

@koeppl koeppl closed this Jan 6, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment