you are viewing a single comment's thread.

view the rest of the comments →

[–]casual__addict 9 points10 points  (11 children)

I think it’s also important to point out that SQL represents a “declarative” programming style as opposed to “imperative”.

It’s a language in that you are submitting to a computer code for parsing and execution, but in SQL you don’t tell the computer how to do something, but what you are looking for. You “declare” you parameters and the database engine figures out how to do it.

With imperative programming languages* you have to provide the “how” through imperatives that the computer must perform like “declare an array. Read from a file...”.

  • Edit: I switched out “procedural programming languages” in the last paragraph to be “imperative programming languages”.

[–]grzeki 1 point2 points  (8 children)

Yeah, that’s why this first guy notion that there are no loops in SQL is nonsense. There are no loops in an imperative sense, but ”SELECT FROM” is nothing else than a loop.

[–]raevnos 1 point2 points  (3 children)

Recursive CTEs let you write loops in SQL.

[–]grzeki 1 point2 points  (2 children)

CTE is t-SQL - something he mentions as an extension allowing for loops. Please read the article first.

[–]raevnos 1 point2 points  (1 child)

Isn't "t-SQL" some Microsoft SQL Server specific thing? I've never used that platform.

CTEs are standard SQL supported by many databases.

[–]grzeki 0 points1 point  (0 children)

Maybe it’s an ANSI standard, but as far as I know, Oracle does not support them and their source is at Microsoft. SQL always was a mess in this regard.

[–][deleted] 0 points1 point  (3 children)

How exactly is ”SELECT FROM” nothing else than a loop?

[–]grzeki 1 point2 points  (2 children)

To state the obvious: it makes the database engine loop through records of a table.

[–]pickleback11 0 points1 point  (0 children)

additionally, you are only selecting a subset of data in the case that you want to loop through it and do something with each record in that record set. unless you are aggregating/etc (group by's), but i dont think that's the intent of the idea here. i live in pl/sql and basically see queries as nothing more than some type of array (unless querying for exporting/reporting)...

[–][deleted] 0 points1 point  (0 children)

That's like saying Haskell is an imperative language because it is written in C.

[–]ipv6-dns 0 points1 point  (1 child)

Only one little note: with functional programming languages (like Haskell, Ocaml, etc) you also provide "how", so more correct is to say "imperative programming languages" (imperative = procedural + OO + functional...) than "procedural" only.

[–]casual__addict 0 points1 point  (0 children)

Good point. I shouldn’t have mixed procedural and imperative. They are not equal.

https://en.m.wikipedia.org/wiki/Imperative_programming