7.5.30 UPDATE

Table of Contents Previous Next



7.5.30 UPDATE
Use an UPDATE statement to modify the data stored in a table. The syntax is:
EXEC SQL [AT database_name][FOR exec_count]
UPDATE [ ONLY ]
table [ [ AS ] alias ]
SET {column = { expression | DEFAULT } |
(column [, ...]) = ({ expression|DEFAULT } [, ...])} [, ...]
[ FROM from_list ]
[ WHERE condition | WHERE CURRENT OF cursor_name ]
[ RETURNING *
| output_expression [[ AS ] output_name] [, ...] ]
database_name is the name of the database (or host variable that contains the name of the database) in which the table resides. This value may take the form of an unquoted string literal, or of a host variable.
Include the FOR exec_count clause to specify the number of times the statement will execute; this clause is valid only if the SET or WHERE clause contains an array.
ECPGPlus provides support for the additional clauses of the SQL UPDATE statement as documented in the PostgreSQL Core documentation available at:
The following UPDATE statement changes the job description of an employee (identified by the :ename host variable) to the value contained in the :new_job host variable, and increases the employees salary, by multiplying the current salary by the value in the :increase host variable:
The enhanced UPDATE statement also allows you to include parameter markers (question marks) in any clause where an input value would be permitted. For example, we can write the same update statement with a parameter marker in the WHERE clause:
This UPDATE statement could allow you to prompt the user for a new value for the job column and provide the amount by which the sal column is incremented for the employee specified by :ename.


Table of Contents Previous Next