pgsql:equery error with parse $n。Error:42601。 #29

Closed
zhangwz opened this Issue Apr 26, 2013 · 1 comment

2 participants

@zhangwz

pgsql:equery(C,"select * from $1",["a_new_table_name"]).
{error,{error,error,<<"42601">>,
<<"syntax error at or near \"$1\"">>,
[{position,<<"15">>}]}}

but this is ok.

pgsql:equery(C,"select * from a_new_table_name;",[]).
{ok,[{column,<<"id">>,{unknown_oid,2950},16,-1,0},
{column,<<"name">>,text,-1,-1,1},
{column,<<"type">>,text,-1,-1,1},
{column,<<"default_value">>,text,-1,-1,1}],
[]}

@wg
Owner
wg commented Apr 26, 2013

Hello, I don't believe PostgreSQL supports passing table names as parameters to a parameterized query. PostgreSQL is pretty strict about where parameters are allowed, so for these sort of queries you'll need to do your own formatting and proper escaping.

@wg wg closed this Apr 26, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment