by chaps · 3y ago · 0 comments
We should write our code to be readable, but it is reasonable to expect that the reader knows the language.
I am sure you know this, so I'm wondering why you consider it data which is outside of your data set. it isn't data when used like this.
There's so many people that want to complain about the conventions of SQL but praise the conventions of other languages and I think its often just "which did you see first?"
...but... this is literally how you write an EXISTS clause in SQL.
> you might as well make it 200 or 1648194
Yes, you can put anything there.
There's lots of funky inconsistent syntax in SQL because it evolved organically over literally the past half century. It has everything to do with the language.
Yes, you can put anything there.
And yes, you missed the point.Also mind you, I use a lot of CTEs, so this would look weird in that context -- hence why using row number sometimes makes more sense and achieves the same thing.
User:
Explain Max/MSP's use of bang.
ChatGPT:
Max/MSP, often simply referred to as "Max", is a visual programming language for music and multimedia. In Max, the fundamental building blocks are "objects" that are connected with "patch cords". These objects can process, generate, or manipulate various types of data, including audio, MIDI, and other control messages.
One of the most basic and essential objects in Max is the "bang". Visually, a bang is represented by a small button in the Max patcher window. Conceptually, a bang is an event trigger. When a bang is received by an object, it tells that object to do something, often to execute its primary function.
Here's a breakdown of how the bang is used in Max:
Triggering Actions: Many objects in Max perform an action when they receive a bang. For example, the metro object (a metronome) sends out bangs at regular intervals. When connected to other objects, these bangs can trigger various actions in a patch.
Flow Control: Bangs can be used to control the order of operations in a patch. The trigger object, often abbreviated as t, is particularly useful for this. It can output a sequence of bangs (and other data types) in a specific order.
User Interaction: The bang object can also be used as an interactive button in a user interface. When you click on it, it sends out a bang.
Feedback: Bangs can be used to provide visual feedback. For instance, when a certain condition is met in your patch, you might use a bang to flash, indicating that the event has occurred.
Conversion: Sometimes, you might receive data, but you only want to know when the data has arrived and not necessarily what the data is. In such cases, you can convert any incoming data into a bang. For example, if you connect a MIDI note input to a bang, the bang will flash every time a note is played, regardless of the note's pitch or velocity.
In essence, the bang is a fundamental concept in Max/MSP, representing an event or a moment in time. It's a way to initiate actions, control the flow of operations, interact with the user, and more.
User:
How about a special value "dang" for propogating mistakes?
The concept of a special value like "dang" to propagate mistakes is an interesting and humorous idea. Let's explore this hypothetical scenario:
Purpose: "Dang" could be used in a system to indicate that a mistake or an error has occurred and has been propagated. Instead of failing silently or producing unpredictable results, the system would clearly mark the affected data or process with "dang".
Usage:
In a programming context, "dang" could be a special return value indicating that a function has encountered an error that wasn't caught but isn't catastrophic enough to halt execution.
In a database, "dang" could indicate corrupted or suspicious data that resulted from a known error but hasn't been cleaned or addressed.
Advantages:
Transparency: Instead of silent failures or cryptic error messages, "dang" provides a clear and human-readable indication of a problem.
Debugging: It could make debugging easier, as developers can quickly identify and trace back the source of "dang" values.
User Experience: For end-users, seeing a "dang" value could be a more friendly or humorous way of being informed that something went wrong, as opposed to a generic error message.
Challenges:
Overuse: If used too liberally, "dang" could become a catch-all for various issues, making it harder to pinpoint specific problems.
Misunderstanding: Without proper documentation or understanding, developers or users might be confused about what "dang" actually represents.
Standardization: For "dang" to be widely adopted, it would need to be standardized across platforms and tools, which is a significant challenge.
In essence, while "dang" as a concept introduces a fun and novel way to handle and propagate errors, its practical implementation would require careful consideration to ensure it adds value to the development and user experience.
Mind you, most of what I write are ad hoc SQL queries where I might write 100-200 queries in a single day. So that sort of thing really adds up. And it's in a strange place where performance isn't dire, since I can work on other stuff while queries chug.
No, it selects a literal integer 1 in all SQL engines.
You can, and do, select any expressions, not only column names.
CategoryId,
CategoryId + 1,
1,
sqrt(CategoryId * ProductId),
Column names alone are expressions too.SQL queries return not columns from table, but a result of relational operations with new columns specified by expressions. What a downvoted user itt cannot accept is that 1 is as meaningful as * or <colname> in general and is an idiom for “columns don’t matter here, only [the number of] rows”. It’s like [[1]].length vs [[id, …]].length. Saying “it’s not my data” is misunderstanding what that data is.
In SQL Server at least, no, it literally means select the integer 1. In the ORDER BY clause, it does mean to order by ordinal position, but that's not a great thing to glorify, since ordinal position is not necessarily stable. I think other dialects like MySQL might allow GROUP BY 1, but that's not a great thing to glorify either.
> SELECT 1 means "select the first column"
interesting.. in postgres this actually gives you a single-column value of 1, in an unnamed column... I haven't used other DBMSes much but expected similar behaviour
PostgreSQL allows a zero-column `SELECT`.
If for ten years you always indented the code this way
Void F()
{ Foo();
Bar();
Baz();}
Then following snippet will seem hard to parse mentally: Void F()
{
Foo();
Bar();
Baz();
}
And vice versaPostgres's dialect seems like it made the right choice here.
It's not superstition. It's people that know deeply how a complex system works picking the option with the best set of side-effects.
I'm offhand a bit surprised IN does worse than EXISTS; I can understand NOT IN being slow, because it has very surprising NULL handling that is hard to optimize for.
(a SEMIJOIN b ON a.x=b.y) JOIN c ON b.z=c.z
This was an impossible structure before, since IN and EXISTS both hide b's columns (all semi- and antijoins effectively come last), and your optimizer will now need to know whether e.g. this associative rewrite is allowed or not: a SEMIJOIN (b JOIN c ON b.z=c.z) ON a.x=b.y
Also, you'll need to deal with LATERAL semijoins, which you didn't before…None of this is impossible, but there's more to it than just a small syntactic change.