title: Custom Doctrine DQL function with Question Mark being converted into parameter
body: <p>I'm using Symfony 2.6 and Doctrine 2.5, i'm trying to make a custom DQL function to implement the "?" Postgres operator (which is used to determine if an element with a certain key exists inside a jsonb field in Postgres) <a href="http://www.postgresql.org/docs/9.4/static/functions-json.html" rel="nofollow noreferrer">http://www.postgresql.org/docs/9.4/static/functions-json.html</a></p>
  
  <p>This is the code (copied from DQL code of <a href="https://github.com/boldtrn/JsonbBundle" rel="nofollow noreferrer">https://github.com/boldtrn/JsonbBundle</a> i just changed the question mark) </p>
  
  <pre><code>class HasElement extends FunctionNode
  {
      public $leftHandSide = null;
      public $rightHandSide = null;
  
      public function parse(\Doctrine\ORM\Query\Parser $parser)
      {
          $parser-&gt;match(Lexer::T_IDENTIFIER);
          $parser-&gt;match(Lexer::T_OPEN_PARENTHESIS);
          $this-&gt;leftHandSide = $parser-&gt;ArithmeticPrimary();
          $parser-&gt;match(Lexer::T_COMMA);
          $this-&gt;rightHandSide = $parser-&gt;ArithmeticPrimary();
          $parser-&gt;match(Lexer::T_CLOSE_PARENTHESIS);
      }
  
      public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
      {
          return '(' .
          $this-&gt;leftHandSide-&gt;dispatch($sqlWalker) . " ? " .
          $this-&gt;rightHandSide-&gt;dispatch($sqlWalker) .
          ')';
      }
  }
  </code></pre>
  
  <p>But the question mark is considered a parameter placeholder when creating the query, I get a Syntax error and inside the query it's replaced by $2 before parameters being set.</p>
  
  <pre><code>SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "$2"
  LINE 1: ...id = r1_.id WHERE r0_.file_id = $1 AND (r0_.attrs $2 $3)
  </code></pre>
  
  <p>Where the query was supposed to be "(r0_attrs ? $1)"</p>
  
  <p>Is there some way to use question mark inside a DQL without it being considered a parameter? I have tried escaping and replacing with the unicode sequence but that didn't work</p>
  
  <p><strong>EDIT:</strong> Although The answer to this question is the same of the one this is marked as duplicate of (use the function rather than the alias operator), the error is different. Doctrine's parsing comes before PDO parameter assignment, if that wasn't the case i would've gotten this error instead:</p>
  
  <pre><code>PDOException: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound: SELECT * FROM tbl WHERE hst ? 'foo'
  </code></pre>
  
  <p>On top of that, only the general procedure is the same, but the specific answer is different (you need to use a different function)</p>