It is common practice to further manage query results in code.

I am not very good at programming requests or database scripts, and I seem to rely on further manipulating the results from the database, rather than wasting time creating a more complete query that would achieve my ultimate goal.

In fact, in some cases, I completely change the nature of the results by combining the values ​​in columns and deleting rows. It’s just easier to manipulate the code in a loop rather than write a more attractive query.

Of course, most of the time I can write a query, and I return the results from the server exactly the way I want to use it. But there are cases when I run the results for further filtering, because I just do not know how to do this in sql, but the coding seems pretty straightforward.

+3
source share
4 answers

It depends. Generally, you should let the database do what the databases are good at filtering, sorting, and combining data. Comprehensive post-query data transformations (business logic), which you usually need to perform in the application code, and not in the request, especially since debugging these things can be terrible in SQL, but relatively painless in the application code.

, (... ), , , SQL, , .

, - ( ), , !), , , , , , . , , . , , .

? , , , ( SQL), .

+3

. SQL , . , , , .

+1

, sql, -, .

+1
source

IMO, manipulate the code as little as possible. Often you can get answers to questions that are close to what you want. However, if you cannot, manipulating data in code is not inherently bad.

0
source

Source: https://habr.com/ru/post/1756820/


All Articles