SQL lexical structure

The minimal SQL instruction that can be executed by the database engine is a statement. It can also be called a command or query. For example, each of the following is a statement:

SELECT car_id, number_of_doors FROM car_portal_app.car;DELETE FROM car_portal_app.a;SELECT now();

SQL commands are terminated by a semicolon ;.

End of input also terminates a command, but that depends on the tools being used: for example, psql would not execute a command when the user presses Enter if there is no semicolon, it would just move to a new line. However, when psql executes a SQL script from a file, the last command is always executed, even without a semicolon.

The following elements form the lexical structure of SQL:

  • Keywords ...

Get Learning PostgreSQL 10 - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.