diff --git a/lib/modules/Sql.pmod/pgsql.pike b/lib/modules/Sql.pmod/pgsql.pike
index db250c529044a6c752ebfa8d055a00c990a1a753..004c5a44edcb05e1fc2744e9deb31cc8b4baf9ca 100644
--- a/lib/modules/Sql.pmod/pgsql.pike
+++ b/lib/modules/Sql.pmod/pgsql.pike
@@ -1932,7 +1932,8 @@ private inline void throwdelayederror(object parent) {
     if(!sizeof(preparedname) || !tp || !tp.preparedname) {
       if(!sizeof(preparedname))
         preparedname=
-          (portal._unnamedstatementkey = unnamedstatement->trylock(1))
+          (portal._unnamedstatementkey =
+           (syncparse ? unnamedstatement->lock : unnamedstatement->trylock)(1))
            ? "" : PTSTMTPREFIX+int2hex(ptstmtcount++);
       PD("Parse statement %O=%O\n",preparedname,q);
       plugbuffer = c->start();