title: Postgres JDBC driver: PSQLException: syntax error at or near RETURNING
body: <p>For some reason the JDBC PostgreSQL driver is adding: <strong>RETURNING *</strong> to the end of select statements.
  Why?</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>protected static final String AUTH_QUERY = "SELECT \"SECRET\" FROM \"user\" WHERE \"NAME\" = :name";
  
  String password = sql2o.open().createQuery(AUTH_QUERY).addParameter("name", username).executeScalar(String.class);
  </code></pre>
  
  <p><strong>Exception:</strong></p>
  
  <pre><code>org.postgresql.util.PSQLException: ERROR: syntax error at or near "RETURNING"
    Position: 47
      at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2161)
      at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1890)
      at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
      at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:559)
      at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
      at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
      at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
      at org.sql2o.Query.executeScalar(Query.java:533)
      at org.sql2o.Query.executeScalar(Query.java:577)
      at org.sql2o.Query.executeScalar(Query.java:568)
  </code></pre>
  
  <p><strong>Data source (JNDI):</strong></p>
  
  <pre><code>&lt;Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext"&gt;
  
      &lt;New id="mydb" class="org.eclipse.jetty.plus.jndi.Resource"&gt;
          &lt;Arg&gt;&lt;/Arg&gt;
          &lt;Arg&gt;jdbc/mydb&lt;/Arg&gt;
          &lt;Arg&gt;
              &lt;New class="com.mchange.v2.c3p0.ComboPooledDataSource"&gt;
                  &lt;Set name="driverClass"&gt;org.postgresql.Driver&lt;/Set&gt;
                  &lt;Set name="jdbcUrl"&gt;jdbc:postgresql://localhost:5432/mydb&lt;/Set&gt;
                  &lt;Set name="user"&gt;user&lt;/Set&gt;
                  &lt;Set name="password"&gt;pass&lt;/Set&gt;
              &lt;/New&gt;
          &lt;/Arg&gt;
      &lt;/New&gt;
  &lt;/Configure&gt;
  </code></pre>
  
  <p><strong>PostgreSQL JDBC driver version</strong></p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
      &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
      &lt;version&gt;9.3-1101-jdbc41&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p><strong>Packet capture</strong></p>
  
  <p><a href="https://postimg.cc/image/gbl2dq4zx/" rel="nofollow noreferrer">https://postimg.cc/image/gbl2dq4zx/</a></p>
  
  <pre><code>No.     Time           Source                Destination           Protocol Length Info
       12 0.175636000    127.0.0.1             127.0.0.1             PGSQL    182    &gt;P/B/D/E/S
  
  Frame 12: 182 bytes on wire (1456 bits), 182 bytes captured (1456 bits) on interface 0
  PostgreSQL
      Type: Parse
      Length: 69
      Statement: 
      Query: SELECT "SECRET" FROM "user" WHERE "NAME" = $1 RETURNING *
      Parameters: 1
          Type OID: 1043
  </code></pre>