Terminology: In the following, there are two kinds of languages understood by PostgreSQL server
- PL/pgSQL;
- I use both "PostgreSQL SQL" and "SQL in PostgreSQL" to refer to the same thing, the default language of the commands received by PostgreSQL server. "PostgreSQL SQL" i.e. "SQL in PostgreSQL" is not the same thing as SQL per SQL standard.
I have found the following observations:
SQL in PostgreSQL and PL/pgSQL both can create functions (actually stored procedures) by their own
CREATE FUNCTION
statements. I read Difference between language sql and language plpgsql in PostgreSQL functionsBut PL/pgSQL allows variable assignment, while I don't find that SQL in PostgreSQL allows variable assignment.
Since PostgreSQL SQL has CREATE FUNCTION
and SQL standard doesn't have stored procedures, is SQL in PostgreSQL at the same level as SQL/PSM standard, instead of as SQL standard only?
Are SQL in PostgreSQL and PL/pgSQL both at the same level as SQL/PSM standard?
What is the relation betw PL/pgSQL and PostgreSQL SQL?
Is PL/pgSQL a procedural extension to SQL in PostgreSQL, but PostgreSQL SQL already has
CREATE FUNCTION
?Is PL/pgSQL an alternative to SQL in PostgreSQL? Can most of what PL/pgSQL can do also be done in PostgreSQL SQL?
If both PL/pgSQL and SQL in PostgreSQL are at the same level as SQL/PSM, which one more closely follows SQL/PSM standard?
Thanks.
More background:
I learned that we have to use DO
command in PostgreSQL SQL to specify using PL/pgSQL, otherwise the commands are just in PostgreSQL SQL.
In MySQL, I never have to do similar things, but just write MySQL commands. So I am not clear why we have both PL/pgSQL and PostgreSQL SQL, and have to use PL/pgSQL in PostgreSQL SQL via DO
command, instead of just using one of them without the awkwardness of mixing PL/pgSQL in PostgreSQL SQL.