Cookie Consent by Free Privacy Policy Generator ๐Ÿ“Œ Is SQL a declarative language

๐Ÿ  Team IT Security News

TSecurity.de ist eine Online-Plattform, die sich auf die Bereitstellung von Informationen,alle 15 Minuten neuste Nachrichten, Bildungsressourcen und Dienstleistungen rund um das Thema IT-Sicherheit spezialisiert hat.
Ob es sich um aktuelle Nachrichten, Fachartikel, Blogbeitrรคge, Webinare, Tutorials, oder Tipps & Tricks handelt, TSecurity.de bietet seinen Nutzern einen umfassenden รœberblick รผber die wichtigsten Aspekte der IT-Sicherheit in einer sich stรคndig verรคndernden digitalen Welt.

16.12.2023 - TIP: Wer den Cookie Consent Banner akzeptiert, kann z.B. von Englisch nach Deutsch รผbersetzen, erst Englisch auswรคhlen dann wieder Deutsch!

Google Android Playstore Download Button fรผr Team IT Security



๐Ÿ“š Is SQL a declarative language


๐Ÿ’ก Newskategorie: Programmierung
๐Ÿ”— Quelle: dev.to

When learning SQL, we often hear the saying that SQL is a declarative language. You just need to tell it what to do, without telling it how to do it, it will find its own implementation method. That is to say, you need to use it only to describe the task objectives without explaining the computational process, which is fundamentally different from conventional procedural languages. Obviously, this programming language sounds much easier to learn and use.

Is it really that good?

Letโ€™s take an example. We use SQL to query the number of female employees in the sales department. This is the written SQL:

Image description
It seems like this, we donโ€™t need to care about the specific calculation process (traversing every record in the employee table, adding 1 to the count if it meets the conditions, skipping if it doesnโ€™t, and finally looking at the count), just state the target to be queried.

Letโ€™s take another example, find the average salary of employees aged above 30 by department:

Image description
It looks good too, here we really donโ€™t have to care about how to group and calculate the average.

Although SQL is still a language with strict syntax, we can only write correct statements after a certain amount of learning. However, if we donโ€™t care about the calculation process, it will still save a lot of efforts.

Letโ€™s take another example: identify the major customers who contribute the top half of sales. If we design the calculation process, it would be like this:

  1. Calculate the total sales revenue of all customers.
  2. Sort customers in reverse order of sales revenue, with the large ones ranking first and the small ones ranking last.
  3. Accumulate the sales revenue of each customer from 0 in this order, and stop when it exceeds half of the total sales revenue. Then the customers that have been traversed are the target customers.

Then, what does it look like to write it in SQL? This is the simplest way I can think of:

Image description
Take a closer look at this SQL statement, which basically describes the above process. There is a sub query that calculates total sales, followed by a sub query that sorts sales in reverse. The window function is used to calculate the cumulative sales of each row in the sorted list. The main query then filters out customers whose cumulative sales are less than half of the total sales. The only difference from the above process is the writing order. SQL starts calculating the total sales revenue later. There is also a slight logical difference, as SQLโ€™s ordered calculations and step-by-step calculations are not good, it is necessary to calculate all accumulated sales before finding the top ones.

This SQL statement is accurately describing such a process. What about describing the task objective without worrying about the computational process?

Letโ€™s take a simpler example: find the top 10 customers with the highest sales revenue.

Some SQL statements are written as follows:

Image description
If using a well-known database, you also need to use subqueries:

Image description
Both of these SQL statements clearly tell us the calculation process: after sorting by sales revenue in reverse, get the top 10. Moreover, in the syntax of this famous database, it is necessary to artificially create a serial number, which means that the database needs to be more clearly told how to calculate.

If we look at a few hundred rows of SQL (stored procedures), we can see more clearly that SQL is still describing the calculation process honestly, and different calculation processes can bring vastly different computational performance and even results.

In fact, any programming language can be said to be a declarative language to some extent: that is, it only needs to care about the goal and not the process.

If you write a program in Java, you only need to care about how variables change, without worrying about the actions of registers in the CPU, but in assembly language, you need to care; Similarly, when using assembly language, you need to care about the values of registers, but you donโ€™t have to worry about how the NAND gate operates in the CPU;

When writing code in SQL, there is generally no need to worry about the specific actions of variables and loops. It does not have the concept of variables, but it has the concepts of tables, fields, and related calculation methods, and you also need to pay attention to the process at this level. In this sense, SQL and other programming languages only have different levels of abstraction in describing problems, and there is no essential difference in explaining processes.

Why do so many people think that SQL is a so-called declarative language? This is because the design of SQL deliberately weakens the โ€œproceduralโ€ feature, and in order to make the statement more like English, it puts basic operations into each clause of a statement. When all the steps involved in the calculation task are basic operations within the abstract level of SQL, it can be written as one statement, seemingly describing the task goal to SQL.

However, conventional programming languages usually do not design multiple basic operations into clauses or function parameters of one statement, and advocate for programmers to combine them. This way, people will feel the need to describe the process and do not have the characteristic of โ€œbeing declarativeโ€.

However, the clause structure of a statement is limited even if it is complex. When the task is beyond the scope of this structure and requires the use of nested subqueries or intermediate results to describe it, the so-called โ€œdeclarativeโ€ illusion of SQL will be exposed. It is still necessary to honestly describe the process and approach. Looking back at the previous example, it is clear to see this point.

SQL is indeed easier to learn and use compared to high-level languages like Java when facing some basic query tasks, but it is not because it has stronger โ€œdeclarativeโ€ features than Java, but because it has a higher level of abstraction in structured data computation than Java.

SQL deliberately weakens the โ€œproceduralโ€ characteristics, such as the absence of intermediate variables, which makes its ability to describe processes very weak. When faced with complex tasks, the difficulty increases sharply, and even some tasks cannot be implemented using SQL alone, because SQL without procedural capabilities is not Turing complete. So, database vendors later have to supplement and invent stored procedures and CTE syntax.

If we invent a language that has a high level of abstraction for data computation while retaining its procedural features, you will find it easier to learn and use than SQL, especially when facing complex business logic. Well, this is esProc SPL.

...



๐Ÿ“Œ Is SQL a declarative language


๐Ÿ“ˆ 34.63 Punkte

๐Ÿ“Œ Is SQL a Declarative Language?


๐Ÿ“ˆ 34.63 Punkte

๐Ÿ“Œ Is SQL a declarative language


๐Ÿ“ˆ 34.63 Punkte

๐Ÿ“Œ Workflow - an experiment in declarative window management


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ CraSSh is a cross-browser purely declarative DoS relying on poor nested CSS var() and calc() handling in modern browsers.


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ Jenkins Script Security 1.49 / Declarative 1.3.4 / Groovy 2.60 Remote Code Execution


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ Decker - Declarative Penetration Testing Orchestration Framework


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ Declarative Programming in Rust


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ Web Request and Declarative Net Request: Explaining the impact on Extensions in Manifest V3


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ vSphere 7 with Kubernetes โ€“ Declarative GitOps Continuous Delivery for Tanzu Kubernetes clusters


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ Pipeline Declarative Plugin up to 1.3.3 Sandbox Converter.groovy Remote Code Execution


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ New in Chrome 90: Overflow Clip, Permissions Policy, the Declarative Shadow DOM, and more!


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ Jetpack Compose: A declarative future for building Android apps | Founder Fridays - November 2022


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ Challenge: Design for declarative device management in your MDM solution


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ Which of the most popular DEs (GNOME, KDE, xfce, other?) has the best support for configuration management and/or declarative configuration


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ How to make declarative/code-based router instead of file-based router in SvelteKit 2


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ Declarative Programming Vs Imperative Programming


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ Using Rust and Leptos to build beautiful, declarative UIs


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ 10 Ways for Kubernetes Declarative Configuration Management


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ Declarative vs. Imperative Plotting


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ useRequest: Create a Basic Declarative React hook for Managing API Requests as an Alternative to useQuery


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ From Imperative to Declarative Angular Development with RxJS


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ Imperative X Declarative


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ Declarative Shadow DOM


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ Declarative Loop Control Flow in Angularย 17


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ Declarative JavaScript


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ The declarative approach in Vue 3, think twice before using `watch` or mutating your state


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ The declarative approach in Vue 3, think twice before using `watch` or mutating your state


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ The issue of recursive module calls in declarative infrastructure-as-code


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ Astro Markdoc: Readable, Declarative MDX Alternative


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ blendOS v4 released, now fully declarative, with support for any desktop environment/packages in the Arch repos


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ [$] Declarative partitioning in PostgreSQL


๐Ÿ“ˆ 22.27 Punkte

๐Ÿ“Œ One of the most useful and underused language in the Linux ecosystem is AWK. Here is "The Awk Programming Language" by its authors


๐Ÿ“ˆ 16.81 Punkte











matomo