LANGUAGE SQL (often written as just LANGUAGE sql in PostgreSQL or LANGUAGE SQL in MySQL) is a clause used inside CREATE FUNCTION and CREATE PROCEDURE statements. It tells the database engine that the routineas logic consists solely of standard SQL statements, not of another procedural language such as PLpgSQL, PL/SQL, Java, or Python. When the clause is present, the server treats the routine as a set of one or more SQL commands executed in the context of the caller, inheriting the calleras transaction and privilege scope.Because SQL is the databaseas native language, routines declared with LANGUAGE SQL are usually parsed, optimized, and executed more efficiently than those written in higher-level procedural languages. However, they lack flow-control constructs beyond what is available in ANSI SQL (e.g., CASE, UNION, subqueries) and therefore suit simple computations, data transformations, and wrapper queries rather than complex business logic.Some systems supply implicit defaults. PostgreSQL defaults to LANGUAGE sql if no language is given and the body starts with SELECT, INSERT, UPDATE, or DELETE. MySQL requires an explicit LANGUAGE SQL keyword when you want to contrast it with LANGUAGE JAVA (deprecated) or other potential languages. Always check your dialectas documentation for exact requirements.
language_name
(identifier) - Name of the language; for this keyword the value must be SQL (case insensitive). No other parameters.CREATE FUNCTION, CREATE PROCEDURE, PLpgSQL, STORED PROCEDURES, SQL PL
SQL/PSM (1996) and PostgreSQL 7.0
It specifies that the body of a stored function or procedure is written entirely in standard SQL, allowing the database to run it without an external procedural interpreter.
Yes, if the function body contains a single SQL command. For multi-statement functions, you must still declare LANGUAGE sql explicitly.
Avoid it when you need procedural features such as loops, variable assignment, or exception handling. Choose PLpgSQL or another procedural language instead.
Yes. MySQL expects LANGUAGE SQL in CREATE FUNCTION to clarify that the routine uses the SQL language rather than other languages like JAVA.