Using Postgres pl/pgsql, I'm attempting to create a table using a dynamic EXECUTE command, such as:
...
DECLARE
tblVar varchar := "myTable";
BEGIN
EXECUTE 'CREATE TABLE $1 (
foo integer NOT NULL,
bar varchar NOT NULL)'
USING _tblVar;
...
However, I continue to receive the error message
ERROR: syntax error at or near "$1"
If I don't use the $1
token and, instead, write the string myTable
it works just fine.
Is there a limitation on using dynamic statements for CREATE calls?
execute ... using
can only use substitutions where you could normally have bind variables - ie not for table names etc – Jack Douglas♦ Sep 6 '11 at 20:50quote_ident
- such as restrict to~'^[a-z]{3,10}$'
and add a prefix – Jack Douglas♦ Sep 7 '11 at 15:49