Ask HN: How do you test SQL?
291–300 of 322 posts
Re: Ask HN: How do you test SQL?
#292Re: Ask HN: How do you test SQL?
#293Earlier quoted context omitted.
No. SQL is almost the _textbook definition_ of a declarative language. It does not define the way. It defines the end result.
You make a statement without reasoning or examples: empty argument. You are not arguing any more, just want to be right. > This is the "texbook definition" The textbook definition of gravity is F=Gx((M1xM2)/r2) According to Newton's textbook. Ask today's physicists about this.
SQL describes WHAT data you want returned. A functional language describes HOW you retrieve that data.
SQL is a declarative DSL for set theory and data transformation. Also precisely why both OO and FP languages fail so miserably with database mapping libraries; the so-called impedance mismatch.
Declares this set joined with that set in this way, and then grab a subset where a condition is true, grouping them according to certain criteria, and putting them in order. All this despite partially being in memory, partly stored on disk, and indexing/performance being orthogonal to the syntax of the query language.
Show me a functional language for some data on disk, some in memory, with varying levels of indexing, and where accessing the information doesn't have any impact on the transformation API.
Re: Ask HN: How do you test SQL?
#294Earlier quoted context omitted.
I mean, I get what you are aiming for. HTML, though, is a markup language. You can call it declarative, but you don't get anything other than the HTML that you create. That is, it is not generating anything. You type what you get. Put differently, it is not a program. SQL is far and away understood as a declarative language for what data you want out of a relational database. I challenge you to find any literature th…
"don't get anything other than the HTML that you create" that's the point of declarative languages "That is, it is not generating anything." if you speak about code generation like code behind in VS, it has nothing do with the paradigm. If you speak about underlying technology, it does not matter. In case of declarative languages, the framework determines what the language is capable of. And that's the point of them,…
SQL: describing the subsets of related data you want and not caring if that data is on disk, in memory, indexed, located on another server, or calculated on the fly. The engine (wait staff and cooks) figure out the "how" and return what you've ordered/queried.
Ergo SQL is a declarative language.
Re: Ask HN: How do you test SQL?
#295Earlier quoted context omitted.
SQL is not a declarative language. It is a functional language, and structured language on the top as extensions. HTML is a declarative language.
SQL is absolutely a declarative language. It is practically the textbook definition of a declarative language.
Re: Ask HN: How do you test SQL?
#296Earlier quoted context omitted.
SQL is not a declarative language. It is a functional language, and structured language on the top as extensions. HTML is a declarative language.
Okay, I'll grant it's not pure declarative. But the part that is declarative is sure difficult to test.
Point to any programming language that is supposed to be a pure example of anything and folks will either find at least ten clear counterexamples in that language within five minutes or demonstrate how it is grossly limited to the point of uselessness for production use on a non-trivial scale.
Re: Ask HN: How do you test SQL?
#297Earlier quoted context omitted.
Okay, I'll grant it's not pure declarative. But the part that is declarative is sure difficult to test.
everything is partly declarative. you can draw a rectangle line by line, or you can put this code into a function or a procedure, and call it declarative, because it is something like that. i did not speak about testing, however what a declarative language can do is defined by the framework under it. so you test that I guess?
You don't draw line by line. You describe what you want and have the engine work it out. Just because that description can be complex such as a definition doesn't detract from this point.
Kinda like SQL. Describe the set of data you want from other sets of data and have the engine work it out. It's set theory. In math, sets can have conditions, can be combined, can be filtered, and all without a single function or loop in sight. Ergo declarative, not functional or imperative.
SQL is a DSL for set theory with some extensions tacked on. You can use functions with SQL, but its core is perfectly adequate without them.
Re: Ask HN: How do you test SQL?
#298Earlier quoted context omitted.
I’ve not encountered your definition of declarative before. SQL is often cited in cs texts as an example of a declarative language. That said, SQL does have a lot of imperative features, but those features are used to declare the result of the sql dml query.
SQL does not make sense as a declarative language to me. How you can say that SQL and HTML is the same by nature? Also I can't see why we can't argue about this against the literature. Saying "you are wrong because 20 years old textbook say you are wrong" is not an argument for me
Re: Ask HN: How do you test SQL?
#299Use a testing framework to mock some database into the DB, run your queries, verify the result. Make sure you have a variety of data you use for tests to fully exercise the surface of logic you expect to hit. Basically, treat the query and database as a black-box for testing like you would another third party API call. I would strongly suggest having a layer of code in your application that is exclusively your data a…
I think the tricky part is DB itself might get funny as time goes by, downstream logic changes might invalidate top level queries that built on now dated assumption Overall data integrity is hard.
Re: Ask HN: How do you test SQL?
#300Earlier quoted context omitted.
Oh, someone else below suggested that DBT in OP may be this: https://docs.getdbt.com/ . Well... I don't know anything about this tool, but from cursory reading, this is the correctness kind of testing that is meant to examine whether the way you defined the schema actually leads to the results you expect in the data. Well... it's not an interesting kind of testing, at least not for me. So, I don't know much about it.…
Depends on what you mean by "the subject". dbt doesn't claim to be a testing tool. Personally I use dbt all the time, while I didn't know about the existence of DBT-2. Different worlds apparently.
Actually happened to me twice (different distros at different times did include Docker, the container management tool as "docker" while more commonly naming it something else, like "docker-engine").
As for dbt. I mean... imagine you are selecting the name for your company, that's in SQL business, and you don't even bother to type into your favorite Web search engine "dbt sql"... I mean, it's definitely a business about DataBases, so, certainly a 3-letter acronym with "D" and "B" in it in that order would be truly unique, right?
I'd bet is that what happened is that these people, just like you, thought "I don't know what that is, so it must be unimportant", and they never stopped to consider that they might not know something important about the field they are in.