kee
kee

Reputation: 11619

Does RedShift Postgresql support Bind variable?

I am accessing AWS RedShift through DBI and DBD::Pg module in Perl and I have some trouble with SQL bind variable. I call prepare with sql statement (? in the place of variable) first and then I call execute with the variable array which needs to be mapped to ? but it doesn't work. It simply spits "syntax error".

My understanding is that this bind variable needs to be supported by the driver and the database itself so I am not sure whether it is a problem of the driver or RedShift but then I am not sure whether my understanding (bind variable support depends on the driver and underlying database) is correct. If someone could clarify, that would be great.

Upvotes: 1

Views: 3858

Answers (1)

altermativ
altermativ

Reputation: 690

Prepared statements are supported, but the correct notation for parameters is $1, $2, ...

From the Redshift Developer Guide:

Prepared statements can take parameters: values that are substituted into the statement when it is executed. To include parameters in a prepared statement, supply a list of data types in the PREPARE statement, and, in the statement to be prepared itself, refer to the parameters by position using the notation $1, $2, ... When executing the statement, specify the actual values for these parameters in the EXECUTE statement.

Upvotes: 3

Related Questions