Why SQL?

Status
Not open for further replies.

Trilby

Ars Tribunus Militum
1,690
Whoa. How did I do that, was sure it was on the front page.


...it must have been when I was searching for threads about foreign programming languages.

It's 4pm on a Friday, I'm calling this a mulligan.

I hope he learned it. There are many things in which I question the value and complexity of relative to use (maven stands out) but SQL is not one of them, not even close.
 
Alamout":3183r8ml said:
Trillby":3183r8ml said:
Pretty much.
(Un)holy thread necromancy, dude!

How do people end up doing this? Were you searching for a SQL thread or something?

On the other hand, it might be fun if Suicidolt came back to tell us how it's gone...

*Ignoring the trolls*

I work with SQL all the time. I think when I wrote this thread I was only using mysql and command line interfaces, but I'm used to SSMS and other tools which saved a lot of the hassle mentioned in this thread. I'm a professional developer, and regardless of the *stupid* way I ask questions, I'm very good at my job (yes, I can prove it, and NO, I won't for a troll like you, person reading this and thinking "he's so full of it").

So *how it went*? Well, in simple terms, there are sometimes better ways to store data than RDBMS, specifically, I used YAML recently for a small project because it was quicker. I still think RDBMS(es?) are...sloppy, but there's a lot worse ways out there (XML Data Storage FTW!). Also, I had a recent joyous occasion when I used an RDBMS to store the relationship between the Database and the Application. That was an entertaining IRC chat/stackoverflow discussion.

In terms of RDBMS, I've never really had any difficulty understanding the relationships, or building queries, which I shouldn't given that SQL was originally designed for business users. It still feels pretty sloppy that we're storing data by hand-typed (often case-sensitive) queries in a world where simple programs often hit a few megabytes in size (think about the number of characters in that program's source code that could potentially break by a syntax error). It's sloppy, but as established thoroughly in this thread, it's well tested. Sure, it'd be great to touch-screen drag fields and tables around and name them with our voice, but there just isn't a decent interface out there that's as tried and true as unix-style commands in a white on black box.
 
Suicidolt":29vk2dik said:
Also, I had a recent joyous occasion when I used an RDBMS to store the relationship between the Database and the Application.

Are you saying that you somehow used an RDBMS as middleman between application and your REAL database, is your prose just excessively flowery to the point of being impenetrable or do you just have no clue what it is that you're gluing together?
 
jxl":25zfhbuh said:
Suicidolt":25zfhbuh said:
Also, I had a recent joyous occasion when I used an RDBMS to store the relationship between the Database and the Application.

Are you saying that you somehow used an RDBMS as middleman between application and your REAL database, is your prose just excessively flowery to the point of being impenetrable or do you just have no clue what it is that you're gluing together?
Maybe he means something like this? ;)
 

C0rinthian

Ars Tribunus Angusticlavius
6,858
Suicidolt":e0o6phol said:
It still feels pretty sloppy that we're storing data by hand-typed (often case-sensitive) queries in a world where simple programs often hit a few megabytes in size (think about the number of characters in that program's source code that could potentially break by a syntax error). It's sloppy, but as established thoroughly in this thread, it's well tested. Sure, it'd be great to touch-screen drag fields and tables around and name them with our voice, but there just isn't a decent interface out there that's as tried and true as unix-style commands in a white on black box.

...what?

When you boil it down, ALL code is hand typed. Sometimes assisted by an IDE, but it's put together by a monkey banging on a keyboard. That's not something that's special about SQL. It's also not case sensitive. The actual DATA might be case sensitive, but that's also not unique to SQL. Finally, there are tools to do the 'drag fields and tables around' stuff if you really want it.

And who is doing all their updates manually at a command line? SQLPlus is awesome and all, but there are tools out there for SQL just like there are for any other programming language.
 

jbode

Ars Legatus Legionis
11,752
Subscriptor
Suicidolt":etoe9dym said:
It still feels pretty sloppy that we're storing data by hand-typed (often case-sensitive) queries in a world where simple programs often hit a few megabytes in size (think about the number of characters in that program's source code that could potentially break by a syntax error). It's sloppy, but as established thoroughly in this thread, it's well tested. Sure, it'd be great to touch-screen drag fields and tables around and name them with our voice, but there just isn't a decent interface out there that's as tried and true as unix-style commands in a white on black box.

At some point it's all hand-hacked; whether it's someone writing the Python to generate the SQL from a web form, or whether it's someone writing the C/C++/whatever to parse and execute the Python and SQL, or whether it's someone writing the compilers to translate the C/C++/whatever into machine code, all the way down to the wireheads typing the specs for their chip designs into the gizmos that lay out the physical pathways on the die, etc.

Yes, we live in the future, but even in the future somebody has to get their hands dirty. That's the difference between technology and magic.
 
jxl":1g6340ck said:
Suicidolt":1g6340ck said:
Also, I had a recent joyous occasion when I used an RDBMS to store the relationship between the Database and the Application.

Are you saying that you somehow used an RDBMS as middleman between application and your REAL database, is your prose just excessively flowery to the point of being impenetrable or do you just have no clue what it is that you're gluing together?

It would be difficult for someone who hasn't ever worked with a database before to understand that the relationships between tables & columns (or fields if you prefer) and the data stored in them are usually placed into the consuming code, and above I was refering to the storage of said relationship in the database. Yay middleware.
 
C0rinthian":3ccdvpei said:
Suicidolt":3ccdvpei said:
It still feels pretty sloppy that we're storing data by hand-typed (often case-sensitive) queries in a world where simple programs often hit a few megabytes in size (think about the number of characters in that program's source code that could potentially break by a syntax error). It's sloppy, but as established thoroughly in this thread, it's well tested. Sure, it'd be great to touch-screen drag fields and tables around and name them with our voice, but there just isn't a decent interface out there that's as tried and true as unix-style commands in a white on black box.

...what?

When you boil it down, ALL code is hand typed. Sometimes assisted by an IDE, but it's put together by a monkey banging on a keyboard. That's not something that's special about SQL. It's also not case sensitive. The actual DATA might be case sensitive, but that's also not unique to SQL. Finally, there are tools to do the 'drag fields and tables around' stuff if you really want it.

And who is doing all their updates manually at a command line? SQLPlus is awesome and all, but there are tools out there for SQL just like there are for any other programming language.

I know this may be difficult for you, but the purpose of programming is to generate reusable bits of "hand typed" code that allows you to think on a higher level and not get bogged down with stupid crap. In the case of SQL, the Entity Framework in .NET does a decent job of removing the SQL from the developer and reusing tried and true code.

And of course, this brings us back to the premise of this thread. There's a reason they call them "Higher level languages". SQL is not very high level.
 
And of course, this brings us back to the premise of this thread. There's a reason they call them "Higher level languages". SQL is not very high level.
SQL is probably the highest level language that most developers (people who use C++ or Obj-C or Java or .NET or Python or whatever) ever use.

You don't even tell SQL how to do what it is you want: you tell it what you want and leave it up to the database to figure out how best to get it. It completely abstracts away details such as resource management or storage and memory layout, and it is built on a sound mathematical foundation (though admittedly, practical SQL systems contain lots of deviations from that mathematical foundation). It's absolutely high level.
 
Suicidolt":2lgpo9zi said:
I know this may be difficult for you, but the purpose of programming is to generate reusable bits of "hand typed" code that allows you to think on a higher level and not get bogged down with stupid crap. In the case of SQL, the Entity Framework in .NET does a decent job of removing the SQL from the developer and reusing tried and true code.
The entity framework is not a language, it is a library to facilitate certain common types of use cases around data.
And of course, this brings us back to the premise of this thread. There's a reason they call them "Higher level languages". SQL is not very high level.
SQL is actually a very high level language. Wikipedia provides some useful insights here:

A high-level programming language is a programming language with strong abstraction from the details of the computer. In comparison to low-level programming languages, it may use natural language elements, be easier to use, or be from the specification of the program, making the process of developing a program simpler and more understandable with respect to a low-level language. The amount of abstraction provided defines how "high-level" a programming language is.

...

"High-level language" refers to the higher level of abstraction from machine language. Rather than dealing with registers, memory addresses and call stacks, high-level languages deal with variables, arrays, objects, complex arithmetic or boolean expressions, subroutines and functions, loops, threads, locks, and other abstract computer science concepts, with a focus on usability over optimal program efficiency. Unlike low-level assembly languages, high-level languages have few, if any, language elements that translate directly into a machine's native opcodes.

...

The terms high-level and low-level are inherently relative. Some decades ago, the C language, and similar languages, were most often considered "high-level", as it supported concepts such as expression evaluation, parameterised recursive functions, and data types and structures, while assembly language was considered "low-level". Many programmers today might refer to C as low-level, as it lacks a large runtime-system (no garbage collection, etc.), basically supports only scalar operations, and provides direct memory addressing. It, therefore, readily blends with assembly language and the machine level of CPUs and microcontrollers.

Assembly language may itself be regarded as a higher level (but often still one-to-one if used without macros) representation of machine code, as it supports concepts such as constants and (limited) expressions, sometimes even variables, procedures, and data structures. Machine code, in its turn, is inherently at a slightly higher level than the microcode or micro-operations used internally in many processors.

Currently SQL is a fairly high level language even in a relative sense as it sits much further up wrt abstraction layers than most other languages.

Furthermore, SQL can absolutely be seen as a high level language because it eschews normal low level concepts like telling the computer how to perform the calculation you want. Instead you simple describe *what* you want. This is extremely different most languages out there (and nearly all the low level ones) and pretty much immediately makes SQL high-level by default. SQL will remain there until there is a *major* shift in programming languages that moves things even higher than that.

Currently there is no such movement.
 

C0rinthian

Ars Tribunus Angusticlavius
6,858
Suicidolt":35tr5dke said:
C0rinthian":35tr5dke said:
Suicidolt":35tr5dke said:
It still feels pretty sloppy that we're storing data by hand-typed (often case-sensitive) queries in a world where simple programs often hit a few megabytes in size (think about the number of characters in that program's source code that could potentially break by a syntax error). It's sloppy, but as established thoroughly in this thread, it's well tested. Sure, it'd be great to touch-screen drag fields and tables around and name them with our voice, but there just isn't a decent interface out there that's as tried and true as unix-style commands in a white on black box.

...what?

When you boil it down, ALL code is hand typed. Sometimes assisted by an IDE, but it's put together by a monkey banging on a keyboard. That's not something that's special about SQL. It's also not case sensitive. The actual DATA might be case sensitive, but that's also not unique to SQL. Finally, there are tools to do the 'drag fields and tables around' stuff if you really want it.

And who is doing all their updates manually at a command line? SQLPlus is awesome and all, but there are tools out there for SQL just like there are for any other programming language.

I know this may be difficult for you, but the purpose of programming is to generate reusable bits of "hand typed" code that allows you to think on a higher level and not get bogged down with stupid crap.

Right, you create reuable bits of SQL code that your application can utilize to interact with your database without you having to worry about the details every time. But regardless, someone has to hand-type those reusable bits of code in the first place.
 
Suicidolt":2w91yjf4 said:
It would be difficult for someone who hasn't ever worked with a database before to understand that the relationships between tables & columns (or fields if you prefer) and the data stored in them are usually placed into the consuming code, and above I was refering to the storage of said relationship in the database.

Is this a self-referential statement? I still have no clue what it is that you're saying.
Are you patting yourself on the back for using a RDBMS? For populating business objects from relational entities?
You are not getting paid by the word here. Prefer clarity of meaning.
 
Suicidolt":29rqlno1 said:
In the case of SQL, the Entity Framework in .NET does a decent job of removing the SQL from the developer and reusing tried and true code.

EF is not the worst ORM that I've run into and for a fair segment of general cases I'm happy to have it around, but using it brings its own set of performance considerations to the table (on top of having some clue about how your underlying RDBMS works).
At the end of the day, sometimes you have to write SQL to optimize performance. It's not that scary!
 

ronelson

Ars Legatus Legionis
21,399
Subscriptor
I know this may be difficult for you, but the purpose of programming is to generate reusable bits of "hand typed" code that allows you to think on a higher level and not get bogged down with stupid crap.
Using SQL to describe even more SQL is certainly generating more reusable bits of "hand typed" code, so at least you got that part right.
 

tb12939

Ars Tribunus Militum
2,157
DrPizza":17hyd679 said:
And of course, this brings us back to the premise of this thread. There's a reason they call them "Higher level languages". SQL is not very high level.
SQL is probably the highest level language that most developers (people who use C++ or Obj-C or Java or .NET or Python or whatever) ever use.
SQL is certainly a high level language (it's far from detail how things are to be done), but it lacks good mechanisms for defining additional abstractions within the problem domain.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
SQL is certainly a high level language (it's far from detail how things are to be done), but it lacks good mechanisms for defining additional abstractions within the problem domain.

Such as? (not necessarily disagreeing, just wondering specifically what)

personally I find the lack of support for aliases within other parts of the query *deeply* frustrating.

Code:
select
 some horribly complex thing here as foo, 
 another big thing as bar
 from x
 where y
 group by foo
 order by bar

Invalid column name foo.

Nastiest most pointless bit of DRY violation I encounter on a regular basis. Do any RDBMS vendors support doing that?
At least order by seems to allow it (is that pretty universal?).
 

A.W.

Ars Tribunus Angusticlavius
6,790
ShuggyCoUk":2tj6z9gn said:
SQL is certainly a high level language (it's far from detail how things are to be done), but it lacks good mechanisms for defining additional abstractions within the problem domain.

Such as? (not necessarily disagreeing, just wondering specifically what)

personally I find the lack of support for aliases within other parts of the query *deeply* frustrating.

Code:
select
 some horribly complex thing here as foo, 
 another big thing as bar
 from x
 where y
 group by foo
 order by bar

Invalid column name foo.

Nastiest most pointless bit of DRY violation I encounter on a regular basis. Do any RDBMS vendors support doing that?
At least order by seems to allow it (is that pretty universal?).

That is pretty universal, yes. I've been using technophile's solution since SQL 2005 (when support for CTEs was added in MSSQL). Order by can use any fields that exist in the finalized data set; all other clauses can only use fields that exist in the underlying data set.
 

C0rinthian

Ars Tribunus Angusticlavius
6,858
technophile":t6f3nt5j said:
Sure:

Code:
WITH (
  some horribly complex thing here
) as foo

SELECT foo.something, bar.somethingelse
FROM aTable as bar
JOIN foo ON bar.field = foo.field
WHERE y
GROUP BY foo.something
ORDER BY bar.somethingelse

SQL Server 2008 and up, IIRC; no idea about Oracle or other RDBMSes, as I've not used them recently.

Oracle as well. Although you may just be moving the group by into the WITH, where the issue still stands. Depends on what the horribly complex thing is.
 

A.W.

Ars Tribunus Angusticlavius
6,790
C0rinthian":25wcixii said:
Although you may just be moving the group by into the WITH, where the issue still stands. Depends on what the horribly complex thing is.

The horribly complex thing is still there, but in the WITH clause, it only has to be specified once, and then referenced wherever it's needed. If you put it inline in your select, you have to repeat the horribly complex thing potentially several times (e.g. in a WHERE clause, if it's being ORed with some other logic).
 

HL7

Ars Praefectus
3,523
Subscriptor++
ShuggyCoUk":1usvg2ph said:
Code:
select
 some horribly complex thing here as foo, 
 another big thing as bar
 from x
 where y
 group by foo
 order by bar

Invalid column name foo.
You can work around this with a subquery (check your execution plan to ensure the result is the same). Depending on how complex your expression is, the subquery may increase clarity. I got exactly the same execution plans with these two queries:
Code:
SELECT Column1, Column2, <expression> AS ExpressionColumn, COUNT(*)
FROM Table1
WHERE <criteria>
GROUP BY Column1, Column2, <expression>
Code:
SELECT Column1, Column2, ExpressionColumn, COUNT(*)
FROM
(
   SELECT *, <expression> AS ExpressionColumn
   FROM Table1
   WHERE <criteria>
) t
GROUP BY Column1, Column2, ExpressionColumn
Also, a CTE is a viable alternative as previously mentioned; personally I tend to favor the subquery when it's used once and a CTE when it's used more than once.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
thanks for all the suggestions, but I still can't help feeling that, requiring them is just plain wrong.

WITH is at least nice because it generalizes even more but still I rack my brains trying to figure out why, given it was decided that it was perfectly fine to use it in order by, they haven't decided to do the same for the group by. I know it's slightly more effort, but making machines do the hard work for is kinda the point.
 

C0rinthian

Ars Tribunus Angusticlavius
6,858
ShuggyCoUk":dr63ex8o said:
thanks for all the suggestions, but I still can't help feeling that, requiring them is just plain wrong.

WITH is at least nice because it generalizes even more but still I rack my brains trying to figure out why, given it was decided that it was perfectly fine to use it in order by, they haven't decided to do the same for the group by. I know it's slightly more effort, but making machines do the hard work for is kinda the point.

I have a feeling it has to do with query execution. ORDER BY happens after the result set has been collected, while GROUP BY is part of collecting that result set.
 

ronelson

Ars Legatus Legionis
21,399
Subscriptor
WITH is at least nice because it generalizes even more but still I rack my brains trying to figure out why, given it was decided that it was perfectly fine to use it in order by, they haven't decided to do the same for the group by.
My first guess would be that one feature came years before the other, or was implemented by two vendors differently until it was standardized. Can't break old code, right?
 
Status
Not open for further replies.