RefLib

Reference library for AI

Back

postgresql_16:7.1.157.4 Examples

PostgreSQL 16 > Reference > SQL Commands > PREPARE > Examples

Create a prepared statement for an INSERT statement, and then execute it: PREPARE fooplan (int, text, bool, numeric) AS INSERT INTO foo VALUES($1, $2, $3, $4); EXECUTE fooplan(1, 'Hunter Valley', 't', 200.00);

Create a prepared statement for a SELECT statement, and then execute it: PREPARE usrrptplan (int) AS SELECT * FROM users u, logs l WHERE u.usrid=$1 AND u.usrid=l.usrid AND l.date = $2; EXECUTE usrrptplan(1, current_date); In this example, the data type of the second parameter is not specified, so it is inferred from the context in which $2 is used.

Back