Live data from Hacker News

Ask HN: How do you test SQL?

news.ycombinator.com

291–300 of 322 posts

Re: Ask HN: How do you test SQL?

#293

Earlier 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.

And today's physicists will say that's a perfectly adequate approximation in your local frame of reference far below the speed of light.

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?

#294
post #118

Earlier 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,…

Declarative: giving your order to the waiter and having the food returned to you fully prepared.

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?

#295

Earlier 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.

Very often literally as well.

Re: Ask HN: How do you test SQL?

#296
post #106

Earlier 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.

And there's the crux of it all. Nothing is pure in this world except perhaps some parts of math. Everything else is an approximation or a corruption.

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?

#297
post #106

Earlier 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?

SVG: Draw rectangles and triangles. If you don't have a script tag in it, totally declarative.

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?

#298

Earlier 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

Further, another way to look at it is, declarative languages specify output, imperative languages focus on the steps to generate outputs. In imperative code, I'm worrying about how instead of what. In declarative code, I'm worried about what instead of how. As in all things, neither of these statements will be absolutes - there are situations and times where a declarative language user will worry about how the query planner will execute, and there are times where an imperative language user will write very much declarative code.

Re: Ask HN: How do you test SQL?

#299
post #103

Use 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.

It is - but that's the specific hardness that you want to capture and cover with your tests. Downstream logic changing and the application being unaware of it is one of the two major dangers these sorts of tests exist to protect against.

Re: Ask HN: How do you test SQL?

#300
post #286

Earlier 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.

Have you ever been burned by trying to install Docker and getting the whole new desktop manager installed because Docker is a widget in that desktop manager (I believe it's in Gnome)?

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.

Post reply on HN