this post was submitted on 11 Jun 2024
136 points (83.0% liked)

Programming

17352 readers
334 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 1 year ago
MODERATORS
 

Title before edit: I hate programming, why did i choose this field

TL;DR: Stupid mistake, made by hours waste.

Basically, I was extracting date from the SQL db, and it was not displaying. I tried everything, heck I even went to chatgpt, and copilot. Two and half hours of trying every single thing under the sun, you know what was the issue?

SELECT task, status, id FROM mainWorkSpace WHERE user_id = @user_id

I FUCKING FORGOT TO ADD 'date' TO THE DAMN QUERY. TWO AND HALF HOURS. I was like, "Ain't no way." as I scrolled up to the query and there it was, a slap in the face, and you know what was the fix?

SELECT task, status, date, id FROM mainWorkSpace WHERE user_id = @user_id

Moral of the story, don't become a programmer, become a professional cat herder instead.

(page 3) 17 comments
sorted by: hot top controversial new old
[–] [email protected] 6 points 5 months ago

Sucks bro. You’re in good company tho

[–] [email protected] 11 points 5 months ago (1 children)

No worries. I’ve wasted more time on lesser mistakes than this. I also once made everyone an admin by forgetting a single ampersand. That was a fun eight hours.

load more comments (1 replies)
[–] [email protected] 26 points 5 months ago (1 children)

You tried "everything" for over 2 hours but never tried the "*" selector?

[–] [email protected] 24 points 5 months ago* (last edited 5 months ago)

User: I've tried everything

Support: Have you tried ?

[–] [email protected] 2 points 5 months ago* (last edited 5 months ago) (4 children)

The reason the date is not in the output is because you didn't include a date column in your SELECT statement.

If you want to include the date in the output, you'll need to add a column that contains the date to your SELECT statement. For example, if you have a column named "created_at" or "date" in your mainWorkSpace table, you can add it to your SELECT statement like this:

SELECT task, status, id, created_at FROM mainWorkSpace WHERE user_id = @user_id

This will include the created_at column in the output of your query.

🤷 Gpt, first try. I don't know what you asked.

[–] [email protected] 8 points 5 months ago* (last edited 5 months ago) (9 children)

Ah I see ChatGPT is being as accurate as ever making up a created_at field completely unprompted. They've already found the correct SQL:

SELECT task, status, id, date FROM mainWorkSpace WHERE user_id = @user_id

Although I would question the sense in calling a date field "date".

[–] [email protected] 4 points 5 months ago

Well I have to defend it here, it explicitly stated

if you have a column named "created_at" or "date"

But yeah anyhow anyone should be able to figure the own solution out with this. Nonwithstanding that if you need gpt for this, you might not have a good time in general.

load more comments (8 replies)
load more comments (3 replies)
[–] [email protected] 41 points 5 months ago (4 children)

In those kinds of situations you need to remember to try to break the problem down into simpler sections to identify where the problem lies. One of the first steps would be to run SELECT * FROM mainWorkSpace WHERE user_id = @user_id and see if that returns anything.

[–] [email protected] 15 points 5 months ago

Was going to say that.

@OP:

One of the main skill a developer must have is being able to troubleshoot properly how their code behave.

Break your code in small pieces, check all of them with unitary test (formal or not) to validate their behavior then move to the next step. Never test everything in one shot or you will be overwhelmed by side effect bugs whom will distract you from the real root cause.

Being a programmer is not just coding but also testing and deploying (even locally).

That won’t avoid you being blocked by a silly mistake for hours, everybody did that at some point in their career, but that will reduce your frustration against yourself when you discover why the bug existed.

Do a pause, go walk, change the topic and the next time you look at your code, you will spot the obvious bug :-)

load more comments (3 replies)
[–] [email protected] 24 points 5 months ago

I’ve been a SQL dev for years. Last week I spent half an hour reading up on why wrapping a bunch of queries in a transaction was giving me incorrect results compared to when they were separate committed statements. I was investigating locking or what might be happening in the execution plan that was throwing it off.

Turns out I just fucked up the where clause. I didn’t even consider the schoolboy stuff. This kind of shit happens all the time.

[–] [email protected] 12 points 5 months ago (2 children)

This kind of stuff happens all the time IMO, we're human and not perfect 🤷‍♂️

I don't know how much of a help ChatGPT would be in this situation without access to your schema, at least with Copilot you can write a comment in the code explaining what you're trying to do and get some usable pointers in the generated suggestion (which takes your codebase into account).

I usually try to get a second pair of eyes on my code if something that seems relatively simple isn't working as expected... As you gain more experience these mistakes will become less common, and easier to spot

load more comments (2 replies)
[–] [email protected] 54 points 5 months ago (7 children)

You didn't add the date field to your query and couldn't work out why it didn't return the missing field for over 2 hours?

Perhaps SQL isn't for you as things get waaaaay more finicky than that.

[–] [email protected] 82 points 5 months ago (2 children)

You’ve never made a silly mistake where you “can’t see the forest for the trees”?

It happens to the best of us

[–] [email protected] -5 points 5 months ago* (last edited 5 months ago) (20 children)

Yes of course, but it's not the sort of thing I'd make a rant post criticising the entirety of programming about.

It's like going to a mathematics forum and declaring "Guyz I forgot to carry a 1, screw Maths."

load more comments (20 replies)
load more comments (1 replies)
[–] [email protected] 10 points 5 months ago (1 children)

You don't know the circumstances. They might have only seen the query results after several processing steps...

load more comments (1 replies)
[–] [email protected] 19 points 5 months ago (3 children)

Seriously. If this broke him it gets so much worse.. but honestly op, this is how you learn what to do and what not to.

load more comments (3 replies)
load more comments (4 replies)
[–] [email protected] 4 points 5 months ago

I'm pretty sure chatgpt caught mistakes like these for me recently and in the past. Just always slap in all your code into the prompt and tell it what you want the code to do step by step. Like with rubber ducky debugging.

load more comments
view more: ‹ prev next ›