EDB Postgres Advanced Server supports dynamic queries by way of the OPEN FOR USING statement. A string literal or string variable is supplied in the OPEN FOR USING statement to the SELECT command:
Where:
name is the identifier of a previously declared cursor variable.
dynamic_string is a string literal or string variable containing a SELECT command without the terminating semi-colon.
bind_arg, bind_arg_2... are bind arguments that pass variables to corresponding placeholders in the SELECT command when the cursor variable is opened. The placeholders are identifiers prefixed by a colon character.
This example shows a dynamic query using a string literal:
The following is the output from this procedure:
This example query uses bind arguments to pass the query parameters:
The following is the resulting output:
Finally, a string variable is used to pass the SELECT, providing the most flexibility: