PostgreSQL 8.0.1 Documentation | ||||
---|---|---|---|---|
Prev | Fast Backward | Chapter 29. ECPG - Embedded SQL in C | Fast Forward | Next |
29.4. Running SQL Commands
Any SQL command can be run from within an embedded SQL application. Below are some examples of how to do that.
Creating a table:
Inserting rows:
Deleting rows:
Single-row select:
Select using cursors:
Updates:
The tokens of the form :something are host variables, that is, they refer to variables in the C program. They are explained in Section 29.6.
In the default mode, statements are committed only when EXEC SQL COMMIT is issued. The embedded SQL interface also supports autocommit of transactions (similar to libpq behavior) via the -t command-line option to ecpg (see below) or via the EXEC SQL SET AUTOCOMMIT TO ON statement. In autocommit mode, each command is automatically committed unless it is inside an explicit transaction block. This mode can be explicitly turned off using EXEC SQL SET AUTOCOMMIT TO OFF.