8.26. PREPARE

Synopsis

  1. PREPARE statement_name FROM statement

Description

Prepares a statement for execution at a later time. Prepared statements arequeries that are saved in a session with a given name. The statement caninclude parameters in place of literals to be replaced at execution time.Parameters are represented by question marks.

Examples

Prepare a select query:

  1. PREPARE my_select1 FROM
  2. SELECT * FROM nation;

Prepare a select query that includes parameters. The values to compare withregionkey and nationkey will be filled in with the EXECUTE statement:

  1. PREPARE my_select2 FROM
  2. SELECT name FROM nation WHERE regionkey = ? AND nationkey < ?;

Prepare an insert query:

  1. PREPARE my_insert FROM
  2. INSERT INTO cities VALUES (1, 'San Francisco');

See Also

EXECUTE, DEALLOCATE PREPARE, DESCRIBE INPUT, DESCRIBE OUTPUT