-
Notifications
You must be signed in to change notification settings - Fork 344
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
Correctness of query: join omitted in output when executing query. #614
Comments
Hi German, Thanks for the flowers and thanks for the report! That sounds scary. However, I can't reproduce the issue? I added a smaller example, see 561cc7e. I also tried your code and received the following (line breaks added for readability):
That's different from what you observed? I wonder what is going on? Is it possible you are linking to an older version of your code? Cheers, |
What was actually happening is that the query printed was another. I fixed it. However, I would like (see above first question) to return the rows from the left table that do not exist in the right table. Note that the key is composite (invitationId + recipe is the primary key in left table and invitationid + recipe is a foreign key in the right table but those cannot be null when a row exists). I cannot use --- This is left table
CREATE TABLE IF NOT EXISTS online_rooms_invitations (
invitation_id CHAR(36) NOT NULL,
sent_date DATETIME NOT NULL,
sender VARCHAR(80) NOT NULL,
recipe VARCHAR(80) NOT NULL,
kind SMALLINT NOT NULL,
PRIMARY KEY (invitation_id, recipe),
FOREIGN KEY (recipe) REFERENCES online_rooms_users(email),
FOREIGN KEY (sender) REFERENCES online_rooms_users(email)
);
-- This is right table, note the NOT NULL in recipe and invitation_id
CREATE TABLE IF NOT EXISTS online_rooms_invitations_replies (
invitation_reply_id CHAR(36) NOT NULL PRIMARY KEY,
invitation_id CHAR(36) NOT NULL,
recipe VARCHAR(80) NOT NULL,
sent_date DATETIME NOT NULL,
action SMALLINT NOT NULL,
FOREIGN KEY (invitation_id, recipe) REFERENCES online_rooms_invitations(invitation_id, recipe)
); However, I need to check this in raw sql, basically, this, and the SELECT online_rooms_invitations.invitation_id,online_rooms_invitations.recipe,online_rooms_invitations.sender,online_rooms_invitations.kind
FROM online_rooms_invitations
LEFT OUTER JOIN online_rooms_invitations_replies ON ((online_rooms_invitations_replies.invitation_id<>online_rooms_invitations.invitation_id) OR (online_rooms_invitations_replies.recipe<>online_rooms_invitations.recipe))
WHERE (online_rooms_invitations.recipe='[email protected]' AND
-- Problem here, I cannot do .is_not_null() from sqlpp11, it seems.
online_rooms_invitations_replies.invitation_id IS NOT NULL); |
Thanks for the confirmation. As for the follow-up: There is an auto query =
sqlpp::select(orsInvitationsTab.invitationId, orsInvitationsTab.recipe, orsInvitationsTab.sender,
orsInvitationsTab.kind)
.from(orsInvitationsTab)
.where(orsInvitationsTab.recipe == userId_ and
not exists(select(orsInvitationsRepliesTab.invitationId)
.from(orsInvitationsRepliesTab)
.where(orsInvitationsRepliesTab.invitationId == orsInvitationsTab.invitationId and
orsInvitationsRepliesTab.recipe == orsInvitationsTab.recipe))); Hope this helps? Cheers, |
Whoops, sorry, had the join still in there. Edited... |
It is solved now thanks. I had several issues. One was the query itself but also that is_null was not incouded and would not compile (undefined) and lead me to think it was bc the row cannot be null but it was bc of the missing include. The left join was correct indeed. Thanks for your fast replies. Closing. |
Hello everyone,
Thanks for this great project. Have a quick question.
Problem
Maybe it is me (likely) but I fail to see why for this query the output omits the join when generating the code to be executed... Joins are not generated.
generates this:
Tables
The text was updated successfully, but these errors were encountered: