Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What kind of language is SQL?

Is SQL a context free language or some other type of language?

like image 426
Abhinav Arya Avatar asked Oct 27 '14 19:10

Abhinav Arya


People also ask

Is SQL a language like Python?

Differences between SQL and Python The fundamental difference is that SQL is a query language primarily used for accessing and extracting data, whereas Python is a general-purpose programming language that enables experimentation with the data.

Is SQL also a programming language?

Given the definition of a programming language as having a certain vocabulary and a specific syntax, SQL definitely qualifies as a programming language. However, it does not qualify as a General Purpose Language (GPL) and is, in fact, a Domain-Specific Language (DSL).


2 Answers

According to https://stackoverflow.com/a/31265136 SQL is not a regular language. The short explanation is that each select query looks like

 SELECT x FROM y WHERE z

and y can be another select query itself, so it cannot be simulated with finite-state machine. As mentioned before, there are some CFGs for SQL standarts in Backus–Naur Form, thereby SQL is nonregular context free language.

like image 52
SGP Avatar answered Sep 23 '22 23:09

SGP


@aquinas wrote:

Do you mean is SQL also regular? CFG's encompass regular languages. So, they aren't mutually exclusive. To answer your question though, SQL is not a regular language.

@MSX wrote:

Just to clarify, a language is context-free when it is generated by a context-free grammar. There're SQL context-free grammar definitions online. Just google around and you'll find some. Here's one, for example.

like image 44
Brian Tompsett - 汤莱恩 Avatar answered Sep 26 '22 23:09

Brian Tompsett - 汤莱恩