EXECUTE <identifier> "(" <parameter-value> { , ... <parameter-value> } ")"The
execute
statement executes an SQL query previously defined and pre-compiled by theprepare
statement. This saves processor time by eliminating the statement compilation step each time the statement is executed.The
<identifier>
specifies the name of the prepared statement. Parameters in the query are substituted where "?
" placeholders are present in the prepared query statement. All parameters must be of typestring
unless explicitly type cast in theprepare
statement. For example, the followingprepare
statement requires that aninteger
value be supplied for the parameterx
:prepare lookup as select * from t where x=?::integer; execute lookup(1);The following example statements demonstrate defining and executing prepared statements:
create table t(x integer primary key, y integer); prepare lookup as select * from t where x=?::integer; prepare lookup2 as select * from t where x=?::integer and y=?::integer; insert into t values (1,10); execute lookup(1); explain execute lookup(1); execute lookup2(1,10); explain execute lookup2(1,10); prepare selfjoin as select * from t as t1 left join t as t2 on t1.y=t2.y; execute selfjoin(); explain execute selfjoin(); execute selfjoin();