this post was submitted on 30 Jun 2024
17 points (100.0% liked)

SQL

2 readers
1 users here now

Related Fediverse communities:

Icon base by Delapouite under CC BY 3.0 with modifications to add a gradient

founded 1 year ago
MODERATORS
17
Guess the intent (aussie.zone)
submitted 4 months ago* (last edited 4 months ago) by Threen@aussie.zone to c/sql@programming.dev
 

I am one of the developers on a very small team and have just found the following query

I would love to hear your ideas for what you think was being attempted here!

SELECT ... FROM client WHERE CAST(ABS(SIN(clientId)) AS BIT) = 0

top 2 comments
sorted by: hot top controversial new old
[โ€“] neidu2@feddit.nl 4 points 4 months ago

I'm not that sturdy with SQL functions, but my understanding is this:

Get the client ID, and use that as input to a sine function to get a new number. Then get the absolute value of this number. Then you cast this as a bit, and you end up selecting all clients who through this lovecraftian horror ends up as 0.

Why?? I have no idea. It looks to me like they want only to select a subset of clientIDs, but with something that is hard to predict but with the same result every time for the same clients.

[โ€“] Threen@aussie.zone 1 points 4 months ago

Update: The original dev does not remember exactly. However they have said that clientId was originally a VARCHAR, so this may have been checking for both '0' or ''

So an over-engineered workaround to a bad datatype perhaps?