8 ms·
Adding OR logic forced us to confront why users preferred raw SQL
- ryoshu 1y agoI still struggle with ORMs. SQL is... declarative. If you're working with multiple RDBMSs, sure? Maybe I want my local dev to be sqlite and scaled be postgres? I've never run into that in production. A DSL on top of a DSL doesn't make a lot of sense.
- dec0dedab0de 1y agoI just want to write one language at a time if I can. I like sql when querying directly, almost as a UI of sorts, but it’s not my favorite when I am just trying to get my code to work, and the database is a relatively minor detail.
- never_inline 1y agoHow do you do conditional filters in pure SQL from a backend Java / Python app, without doing string concatenation? Not a fan of all the proxy object circus ORMs do but I'd leave row-> domain object mapping and filter building to some library. Sweet spot is probably something akin to Android Room / Micronaut Data JDBC.
- paulddraper 1y agoString concatenation
- Xss3 1y agoNo, we must build 16 more layers of pointless abstraction in a new DSL.
- minitech 1y agoQuery builders that operate at the SQL level. (A popular example of that in Python is SQLAlchemy Core, but there are better ways to do it, especially in better-typed languages.)
- yencabulator 1y agoI was just pondering, for a little Rust project of mine, whether to suffer some weird ORM-smelling query builder, or to just build the AST with https://github.com/apache/datafusion-sqlparser-rs/ https://github.com/apache/datafusion-sqlparser-rs/ and convert to string..
- crazygringo 1y agoWhat's wrong with string concatenation?
- t-writescode 1y agoSimpler SQL injection risk and more testing to make sure all potential branching paths don’t result in invalid SQL.
- webstrand 1y agoThere's zero danger of sql injection so long as everything is being passed by parameters. You just concatenate placeholders when you need string concatenation to build the query.
- crazygringo 1y agoExactly this. And if you're testing, you've got to test every query combination anyways. It's not just syntax that can be wrong, but logic and performance.
- whatevaa 1y agoGuaranteed source of bugs in complex cases.
- crazygringo 1y agoMore complex cases are more likely to have bugs period, just in their logic. String concatenation isn't really a major source of that. Just make sure your parentheses match, as you need to do no matter what, and include a space at the start and end of each string to make sure you don't accidentally smush terms together likethis.
- foobazgt 1y agoJOOQ (http://jooq.org http://jooq.org) is pretty fantastic for this, and it's my go-to for working with RDBMs' on the JVM. It provides a DSL-like API that lets you write pretty much any SQL you need in a type-safe way (without string concatenation).
- sgarland 1y agoSQL has CASE statements, if you’d really like to have all branching logic in pure SQL.
- chillfox 1y agoMy main issue with ORMs is they always end up being just another thing to learn, adding needless complexity. They are not an alternative to SQL as you always end up having to understand what kind of SQL they create and how it works for either performance or complex queries.
- t-writescode 1y agoHand-rolling SQL inside another programming language comes with some unpleasantness, like protecting against SQL injection and making sure the SQL is valid, especially when hand-constructing the query based on input parameters: “sort ascending? Descending? Filter all but things in this group? etc.” Parameter management in some languages are unpleasant, like how JDBC only has positional arguments; and any time you do string concat in a language, you start getting in danger of misformed SQL. Ultra basic ORMs, like Exposed (Kotlin), are well-tested frameworks that do exactly what I want. Want a single value in the =? Or want it to be an “in”? Or what if it’s null? Handled. No special string management. Want parameters? Handled. When I see pure ORM’d code, I can feel safe expecting it to be protected from injection and formatting issues. It’s reduced cognitive load and greater safety. When I see raw string SQL management, I have to put another layer of care and attention to try and make sure (and maybe still fail) there’s no application-crashing mistakes in that part of code. It’s kinda like working with typed and compiled code. Greater protection from error.
- monkeyelite 1y agoYou’re arguing against a straw man. All major language sql libraries are not based on string manipulation and provide things like escaping, arguments, etc out of the box.
- ameliaquining 1y agoOnly for parameterization over scalar values. If you want to do any kind of composition more sophisticated than that, you're either stitching together strings or using some kind of more heavyweight abstraction like an ORM.
- monkeyelite 1y agoThat’s because the composition is supposed to be inside sql. Views, functions, etc. This is another reason why the ORM is a leaky abstraction - it hides all the best features from you.
- lmm 1y agoSQL is just extremely bad on top of being poorly integrated with the host language. Middle-endian order, terrible abstraction capabilities, no test support to speak of, essentially no project management tooling... I use ORMs so that I can write the thing I want to do in a vaguely reasonable language, just like I manipulate XML datastructures in code instead of writing XSLT.
- ozgrakkurt 1y agoCan’t relate this comment to the article. They can’t just run user sql on DB because they are changing internal db schema between releases. And they can’t implement real sql because it is massive compared to some simple query dsl
- jerf 1y agoAt the risk of getting run off this site... Jira's search query widget, which allows in some sense nearly arbitrary SQL while providing syntax completion, making sure you don't run off the rails with actual arbitrary SQL, and supporting very deeply nested conditionals correctly is probably one of the most impressive things to me about that system. I just wish it was not such a staggeringly large pile of work to get to such a thing in other systems. Even if someone cites some sort of open source library that supports this, simply defining to that library what columns and operations you support would be a lengthy task of specification, refinement, and testing. It'd be neat if you could let more users just have SQL but there's so many ways for that to go terribly wrong nowadays, with all those nice juicy SQL features that so many engines now support.
- giveita 1y agoJQL is a very powerful tool. No one sets up Jira perfectly. Not at first. People use anything like a label: the epic, the release version. etc. And JQL let's you get around that in the short term and find stuff.
- crabmusket 1y agoSomething I have been considering is a ETL pipeline that, for each customer in our system, writes only their data to a SQLite file. Then, just expose a full SQLite query facility on that file. This only works when your customers are of a reasonable size (e.g. small businesses or individuals) but could provide arbitrary analytics power. It's also a safe target for AIs to write sql against, if you're into that sort of thing.
- sixdimensional 1y agoIf you're writing out data for analytical read only use - go with DuckDb all the way, over SQLite.
- crabmusket 1y agoThanks, I will look into it!
- monkeyelite 1y agoIs it actually hard to build a DSL for the kind of query’s they are talking about? Seems like it would be a 50 line SICP exercise.
- ameliaquining 1y agoConveniently, it's open core, so you can look: https://github.com/SigNoz/signoz/tree/main/pkg/querybuilder https://github.com/SigNoz/signoz/tree/main/pkg/querybuilder Seems to be 3978 lines of Go at present.
- ecshafer 1y agoGo is pretty wordy, so 50 lines of scheme would be a bit of an exaggeration, but a good enough schemer could probably get it down there
- giveita 1y ago> v3 couldn't do this. No OR support. No complex boolean expressions. No parentheses for precedence. This wasn't a minor limitation; it was a fundamental capability gap. Users were forced to learn ClickHouse SQL, write raw queries, and maintain them as our schemas evolved. We'd built a query builder that couldn't handle real-world queries. What is it with the LinkedIn style? No X No Y No Z Isn't A its B
- outlier99 1y agoIt's not LinkedIn style, this is how ChatGPT generates text
- jjani 1y agoIt's not just ChatGPT—it's part of the inner fabric of Large Language Models. Heh. But seriously, all frontier models do it, it's in the top 3 of tells that even someone with zero LLM experience can spot.
- ak_builds 1y agoThis article is part of our launch week and our main distribution channel is LinkedIn. Our articles are now being read by stakeholders beyond our ICP. I agree that LinkedIn/ChatGPT style isn't the best route. We cringe on it too. We are experimenting to find a middle ground between what gets more reach, while not giving into the trending writing styles. Can I please get some more feedback from you? - would you prefer more technical details in this article? - or just a change in the sentence structure that is more natural (like this response)? - or both?
- tux3 1y agoThe technical content is okay, but there's some fluff with a characteristic LLM signature that cheapens the whole thing. Instead of an article hand-crafted by human hands, it screams to the reader that they are currently reading slop. I would rather not read other people's slop. I could pass your article through an LLM myself, if I wanted that. Here's just one of the most tired snowclones that current LLMs love, everywhere in your content: >This wasn't a minor limitation; it was a fundamental capability gap >context-switch not just between data types, but between entirely different mental models of how to query data. >This wasn't something we asked them to do. They discovered that the query builder could now handle their complex cases, and they preferred it over raw SQL. >That's not just a technical achievement. That's validation that we finally understood the problem we were trying to solve. It wasn't just a minor stylistic issue; It was a signal to close the page.
- est 1y ago> Stop making decisions for users. yes! please stop making webpages background dark. It's a terrible design for ppl with astigmatism like me...
- ak_builds 1y agoThank you for educating me on astigmatism. I wasn't aware of the condition. We are revamping the design. I'll ensure I understand more about this and make it more accessible. Devs seem to prefer dark theme across the brand (eg Supabase, Linear). Hence, the current choice.
- aitchnyu 1y agoIts more straining for this myopic glasses user, and screen sharing/remote desktop artifacts are worse.
- prpl 1y agoSalesforce’s SOQL, like was mentioned with Jira’s JQL, also handles this type of thing _okay_ without explicit joins. I think “SQL is the interface” even for telemtry is the thing that truly makes sense, but it is messy with logs compared to splunk for example
- shakna 1y agoSoQL's lack of joins and subqueries makes it a real pain in my life. `having` and `group by` are not enough when doing a lot of things - like confirming data migration of 40m objects. Can't do a query builder in one step, or must write Apex.
- ankitnayan 1y agoand here query builder helps by making it earier to do cross-signal joins and subqueries. I see that is upcoming in SigNoz https://signoz.io/blog/query-builder-v5/#what-we-couldnt-ship-yet-the-future-of-cross-signal-correlation https://signoz.io/blog/query-builder-v5/#what-we-couldnt-shi...
- gm678 1y agoI hate getting that 'is this LLM output?' feeling halfway through so many articles these days. The article is good but sentences like "This wasn't a minor limitation; it was a fundamental capability gap." are painful to read. > Currently, logs and traces live in separate worlds. You can see that a trace has an error, and you can see related logs, but you can't query them together. I've looked into SigNoz a few times but still using Grafana. The former does look promising, and features like this would start to make the case for maybe switching.
- ankitnayan 1y agoYou might also like the interactive dashboard feauture that was released in the recent launch week https://www.youtube.com/watch?v=YQTQXq0F5Iw&ab_channel=SigNoz-OpenSourceObservabilityPlatform https://www.youtube.com/watch?v=YQTQXq0F5Iw&ab_channel=SigNo...
- flowerthoughts 1y agoOne of my guiding principles is "avoid indirection unless you add abstraction." If what you're doing is a query language, then keeping that transparent and using existing languages is a good idea, unless you can motivate a new language with a new mental model. E.g. it might be better to write an SQL query validator than a DSL.
- foxglacier 1y ago> hide complexity to "simplify" the experience This is a chronic problem in software. What I do instead is either omit the complexity or make it as visible as everything else. If it's not worth making it discoverable, it's not worth having. If you omit it, you get customer feedback about its importance instead of them struggling in silence.