Hacker News new | ask | show | jobs
by hibikir 4446 days ago
In theory, SQL is a declarative programming language, in practice, past the simplest of examples, there are dozens, if not hundreds of ways to ask the same question, and each one of them performs differently. The moment one starts to do things like add anonymous views, the declarative facade tends to disappear.

Let's also remember that many companies stuck with big RDBMs systems have entire teams of people whose job includes turning declarative statements into extremely procedural ones.

So in practice, writing a SQL statement has little to do with making a query readable, but with abusing knowledge of internals to make it work fast. So declarative, not so much.

2 comments

SQL-the-language is declarative - it defines meaning and does not define execution strategy. Particular implementations have significant differences in implementation strategy depending on the way the SQL was structured, leading to crazy results when people try and control operational semantics. But that doesn't mean "SQL is not declarative" - it's just a weakness of declarative languages when we care about operational semantics.

Has anyone made an RDBM that let you write SQL and separately control how it is evaluated?

Sure, but there is continuum here. It's not a binary decision.

For example, I consider the sublanguage in printf to be more declarative than the rest of C as well.

SQL as it stands, especially in contrast to what the existing models were at the time it was introduced, such as CODASYL.

SQL is the one language we use that somewhat operates at the level of thought.