Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NULL values are being inserted when working with compound keys. #2

Open
lutzmi opened this issue Nov 23, 2022 · 5 comments
Open

NULL values are being inserted when working with compound keys. #2

lutzmi opened this issue Nov 23, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@lutzmi
Copy link

lutzmi commented Nov 23, 2022

Hi,

when working with compound keys, NULL will be used as the value for the keys even though they were given. Executing the given sample project the resulting record in the database will be: NULL, NULL, First, Last, 22. I would have expected that the result would be 1, 2, First, Last, 22.

It seems that the generated insert SQL is ignoring the compound key:
/// SQL toINSERTa record into theperson` table.
public static let insert = #"INSERT INTO "person" ( "first_name", "last_name", "age" ) VALUES ( ?, ?, ? )"#

/// SQL to `INSERT` a record into the `person` table.
public static let insertReturning = #"INSERT INTO "person" ( "first_name", "last_name", "age" ) VALUES ( ?, ?, ? ) RETURNING "person_id", "another_id", "first_name", "last_name", "age""#`

Is there a way to work around that?

Thank you!

@helje5 helje5 added the bug Something isn't working label Nov 23, 2022
@helje5
Copy link
Member

helje5 commented Nov 23, 2022

Probably a bug that needs to be fixed.

@lutzmi
Copy link
Author

lutzmi commented Nov 23, 2022

Thanks for the quick response :-)

@helje5
Copy link
Member

helje5 commented Nov 23, 2022

While I've prepared everything to support compound keys, I really didn't test those. Quite likely that some things are wrong with those, tbh I didn't expect many people to use them ;-)

@helje5
Copy link
Member

helje5 commented Nov 23, 2022

Quite likely it incorrectly detects those as automatic primary keys, maybe because they are INTs, ignoring the fact that they are compound keys.

@lutzmi
Copy link
Author

lutzmi commented Nov 23, 2022

Yep, using TEXT instead of INT seems to work as expected.
(You still may be right with your assumption as I am just one person ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants