Live data from Hacker News

Ask HN: How do you test SQL?

news.ycombinator.com

301–310 of 322 posts

Re: Ask HN: How do you test SQL?

#301

Earlier quoted context omitted.

Can split test regime so that as much as possible is covered with SQLite, and then have a second test phase with a heavyweight db only if the first phase passes. So code errors, malformed SQL, etc. cause it to fail fast and early, and you only test with the real DB once you know everything else is working. Or along similar lines you could divide it such that developers can test things locally on their machines with S…

That still doesn't fix the compatibility issues. Postgres has features/syntax that sqlite does not have, so you can't test postgres syntax with sqlite sometimes

That's fair enough.

I meant in situations like parent comment where you're using an ORM such as hibernate that supports multiple databases, you can test as much of the non-DB specific stuff with SQLite in-memory and then do a separate batch of tests with DB specific behaviour.

Re: Ask HN: How do you test SQL?

#302

There's pgTAP for Postgres [1], the same approach probably is valid for other databases. Here's [2] a slide deck by David Wheeler giving an introduction into how it works. [1] https://pgtap.org/ [2] https://www.slideshare.net/justatheory/unit-test-your-databa...

We used to use pgtap extensively, but ended up removing it in favour of testing queries as part our regular nodejs application tests, via a db client - the ergomonics of the test tooling is far better, and I don't think we really lost anything.

Re: Ask HN: How do you test SQL?

#303

Earlier quoted context omitted.

So you test against a different database technology than the one you software uses? I understand why that works but it seems odd

A real nice thing about Postgres and Mysql is that in the JVM world the H2 and HSQLDB engines have large compatibility, you can use them in-JVM for unit test speed in many cases. Doesn't help developing the SQL, does help with testing. Snowflake, on the other hand, is just special.

I assume this can't be done with Oracle DBs

Re: Ask HN: How do you test SQL?

#304
post #293

Earlier quoted context omitted.

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 impeda…

Oh, man, you opened my floodgates pretty well. I feel I have to mention that everything I write is my opinion, and not absolute truth. I reject the idea of absolute truths anyway.

That textbook example was just about how our understanding improves over time, and how a textbook, or all of them is not absolute truth, and debatable, which is what I am doing exactly.

>SQL describes WHAT data you want returned. A functional language describes HOW you retrieve that data.

You need to phrase more precisely here, HOW and WHAT could be interpreted by your own way.

>SQL is a declarative DSL for set theory and data transformation.

Yes, exactly. Now think about lamdba expression added to a generic imperative languages. Isn't that doing the same thing? A set, transform and filter elements of the set like how you do it in SQL with record, but in this case with objects of classes? Are lamdba expressions functional or declarative? Is LINQ functional or declarative? If you say SQL is declarative, than those should be too, or am I wrong? Or LINQ is declarative, but lambda expressions are functional?

>Also precisely why both OO and FP languages fail

I disagree. OOP failed because most programmers did not understand it. I would argue if they are failed, but now I just go with your premise, and assume they are failing. I see the real reason behind this is multifaceted, and mostly coming from the stupidity of design patterns, software architects making too much money in big companies, so they have to deliver something, so creating overconvoluted abstractions, think about the java enterprise hell. Not understanding why restricting yourself as a programmer actually benefits you in the long term, and helps other people understand your sh*t, because it forces you to be more organized. But instead of this, we have classes with a million interface slapped on it. Just ask the average programmer what is a difference between an interface and an abstract class (or have they used it ever), maybe they gonna ask what is an abstract class.

Functional languages are not failing. Pure ones created for certain purposes, like experiment (proof of concept), scientific use, etc and their ideas make their way into all the popular imperative languages, like javascript or c#, where are really useful tools while not caring about the pristine philosophy behind them, just a really useful tool.

>database mapping libraries

I also would not bury them. I exactly know what are you speaking about when you mention "impedance mismatch". I actually wrote my own mapper, i dont dare showing the code to anyone, it's just a mess, and the performance is horrible, but instead "mapping out the database and showing them as object" I built it for forcing the OOP ideas into the database level, so you can have e.g. inheritance. And not how MS solved this in entity framework like by basically denormalizing the structure and smahing together the data, no, my code exactly knows which tables to go to put together one object, which can have multiple level of inheritance. I also introduced the OOP ideas of aggregates and composites, which is exactly my attempt to solve the impedance mismatch problem you mentioned before. Correct me if we don't speak about the same thing.

You speak about technical details of SQL server internal processes, I approach this question strictly from theoretical standpoint, analyzing the language itself, and categorizing them, without thinking of computers. The problem solving approach is my divide, not anything about implementation. I wrote about this a lot in other comments.

Re: Ask HN: How do you test SQL?

#305

Earlier quoted context omitted.

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

"Declarative language" does not mean "free of computation". It does mean the language generally specifies an output. HTML does have computation in the form of tags. What makes HTML and SQL declarative instead of imperative is that in both SQL and HTML the document specifies an specific output that is wanted from the browser (in HTMLs case) or database (in SQLs case). Your earlier example of SELECT (1+3); is something…

I never meant "free of computation", I actually mentioned a lot that forget computers and softwares, and focus on languages.

is Javascript, not html (I mean what's inside), they just smashed together.

>specifies an specific output

That specific output definition is really different.

Consider this:

-task: give me even numbers

-imperative approach:

for i=1 to 100

  result += i * 2
next

-functional approach

return [1,2,3,...].select(x=x * 2)

-declarative approach (not possible, but for the sake of example)

EVEN NUMBERS = NUMBERS LIKE 2,4,6 AND CARRY ON What i wanna ask you to re-explain these examples with your understanding of classification, but using the same task.

>Reality is that declarative languages would be little more than file formats without access to computation.

That what HTML is. A declarative language and a file which requires a framework.

> Your earlier example of SELECT (1+3); is something that can be done in HTML (many different ways), too.

No, not with strictly sticking to the standard and not use any trickery. HTML was not designed to do any kind of calculation. That's why javascript came later.

Re: Ask HN: How do you test SQL?

#306

Earlier quoted context omitted.

thats a huge amount of work and money. at my company they just told us to stop reporting edge cases. much easier, much cheaper.

Sounds like a place that's not really interested in solving customer needs. :( Most places aren't like that, at least the ones I've seen. :)

im not saying its right im just saying thats how it is, apparently i shouldnt joke about that stuff because i was downvoted to minus three.

our website crashes when the user types a double space. their solution is to have us tell users to stop typing in double spaces. since it only happens a few times a month its not considered a high priority. (details have been edited to protect the innocent)

Re: Ask HN: How do you test SQL?

#307
post #294

Earlier quoted context omitted.

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

Imperative: following and executing a cooking recipe

Functional: being multiple line cooks, the food is transformed step by step by different cook, they do the same thing on multiple half-ready dishes.

Declarative: giving your order to the waiter and having the food returned to you fully prepared SQL: getting elements of the a set and by DOING different kind of transformations (line cooks) and removing some plates (a guy standing there and if he sees a plate, which is a different dish, he tossed it to the trash). The end result is the set of data you want.

Ergo SQL is a functional language.

Re: Ask HN: How do you test SQL?

#309

Earlier quoted context omitted.

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…

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

That's right, in practice everything is more like a mishmash of everything. Your function library could be seen as a declarative language over the top of a generic language.

Re: Ask HN: How do you test SQL?

#310

Earlier quoted context omitted.

Technical and implementation details again. When we speak about programming paradigm, we speak about the language alone, not any software system, this is a theoretical discussion. It does not matter how it is executed, what matter is how you express yourself in that language to achieve your goals. There are no bits, bytes and cpus in this conversation. This is classification and taxonomy of artificial languages creat…

> this is a theoretical discussion With all due respect, I don’t understand what your aim is with this discussion, and at this point I think I’m more confused than when we started. What is your aim here? > If HTML is a programming language or not, it's debatable I suppose to some degree, everything is debatable. But this point isn’t somewhere where we’re going to find common ground. Another commenter said it well — w…

Thank you for actually listening and trying to communicate with me, instead of just shooting ad-lib responses like "it's in the textbook so that is that".

I don't really have an aim, I just made a simple statement, and after that everything is back and forth. Classification of languages has no practical implication (or not too much), what it changes is how they are taught, like "INTRO TO PROGRAMMING 101 BEGINNER CLASS FOR DUMMIES"

>I suppose to some degree, everything is debatable.

I just wanted to say that i dont think it's important to decide if HTML is an actual programming language or not, I see it as a language that defines something for a computer. We can just put all alikes into the "Markup-not-programming-language" basket, and that invalidates all of my arguments. I feel in this case there is no big difference in functional/imperative vs declarative languages assuming most of the people's different-than-mine classification, so why even bother then?

Post reply on HN