postgresql_16:5.3.3.1 Executing SQL Statements
PostgreSQL 16 > Client Interfaces > ECPG — Embedded SQL in C > Running SQL Commands > Executing SQL Statements
Creating a table: EXEC SQL CREATE TABLE foo (number integer, ascii char(16)); EXEC SQL CREATE UNIQUE INDEX num1 ON foo(number); EXEC SQL COMMIT;
Inserting rows: EXEC SQL INSERT INTO foo (number, ascii) VALUES (9999, 'doodad'); EXEC SQL COMMIT;
Deleting rows: EXEC SQL DELETE FROM foo WHERE number = 9999; EXEC SQL COMMIT;
Updates: EXEC SQL UPDATE foo SET ascii = 'foobar' WHERE number = 9999; EXEC SQL COMMIT;
SELECT statements that return a single result row can also be executed using EXEC SQL directly. To handle result sets with multiple rows, an application has to use a cursor; see (see postgresql_16:5.3.3.2) below. (As a special case, an application can fetch multiple rows at once into an array host variable; see (see postgresql_16:5.3.4.4).)
Single-row select: EXEC SQL SELECT foo INTO :FooBar FROM table1 WHERE ascii = 'doodad';
Also, a configuration parameter can be retrieved with the SHOW command: EXEC SQL SHOW search_path INTO :var;
The tokens of the form :*something* are *host variables*, that is, they refer to variables in the C program. They are explained in (see postgresql_16:5.3.4).