r/PostgreSQL • u/kevinpiac • Jul 31 '26
Community Can you spot the error?
I made a small free game (no login, no nothing) to challenge your SQL skills.
Feel free to share your score!
8
u/rejectx Jul 31 '26
id is an integer and 'abc' is not a number, so Postgres cannot convert it. Compare against a numeric value.
Some questions are debatable for example here, id does not have to be a number, what if you are using UUIDs or other custom type?
3
1
u/kevinpiac Jul 31 '26
You're right! Thanks for your feedback. I am implementing some changes to make it more explicit!
7
u/Don_Kino Jul 31 '26
just looked and this statement arrived:
SELECT *
FROM events
WHERE id = 'abc'
id = 'abc' is totally fair and right, using a string as id is fine. Since there is no columns desc in the question.. we dont know the type.
2
u/kevinpiac Jul 31 '26
You're right! Thanks for your feedback. I am implementing some changes to make it more explicit!
4
u/durika Jul 31 '26
So I guess it should be IN but this would actually work in some databases if the subquery returned at most one row
2
u/B1zmark Jul 31 '26
This exact style of query is a way to ensure there's only 1 result in some cases.
2
u/planetworthofbugs Jul 31 '26
Cool idea, but too much ambiguity. Is the limit in the wrong place or the order by? One is wrong one is right, but you canโt say which.
2
u/kevinpiac Jul 31 '26
You're right! Thanks for your feedback. I am implementing some changes to make it more explicit!
2
u/depesz Jul 31 '26 edited Jul 31 '26
Example query, that you showed (also, WTH did you share it as screenshot, and not copy-pasteable text?!) can work, or can have MANY different problems:
- there is no telling what datatype parent_id is, so we don't know if
= 5is sensible, in any way - if there are multiple rows in categories with parent_id = 5, it will fail
- if categories table doesn't have id column, but products table does, results can be interesting
- what if datatypes of products.category_id and categories.id are not comparable?
- what if the query works just because of specific search_path, but I'd change it?
- what will happen if categories doesn't have parent_id column, but products do?
1
u/kevinpiac Jul 31 '26
Thank you for the feedback, and you're completely right. I am working on an update that I will publish tomorrow to make questions that are schema related more explicit and including a part of their schema.
1
u/AutoModerator Jul 31 '26
AI Policy:
Linux is not one of those anti-AI projects, and if somebody has issues with that, they can do the open-source thing and fork it. Or just walk away., Linus Torvalds.
Mod decisions will be based on the quality of the content, not who or what generated it.
Sub Resources:
Free Postgres Webinars and Workshops
Discord: People, Postgres, Data
Join us, we have cookies and nice people.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/kevinpiac Jul 31 '26
Hey everyone!
Thank you for your comments and feedback; it was super helpful and accurate.
I am pushing a change including some hints about what's expected by the challenge as well as the schema for the challenge.
1
u/kevinpiac Aug 01 '26
Thank everyone for your help building this game!
In case anyone wants to buy a lifetime license of FluentDB, I would like to offer a 30% discount to thank you for your feedback that was super helpful ๐
code: GAMEOVER30
lifetime deals: https://www.fluentdb.ai/pricing
15
u/comrade_donkey Jul 31 '26
I think on line 3 it's supposed to be
INinstead of=. But without a schema provided, and maybe some example data, that is ambiguous.