Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have run into the same frustrating issue. Sometimes the <code>AS</code> keyword would have its intended effect, but other times it wouldn't. I was unable to identify the conditions to make it work correctly.</p> <p><strong>Short Answer:</strong> (Thanks to Simon Urbanek (package maintainer for RJDBC), Yev, and Sebastien! See the <strong>Long Answer.</strong>) One thing that you may try is to open your JDBC connection using <code>?useOldAliasMetadataBehavior=true</code> in your connection string. Example:</p> <pre><code>drv &lt;- JDBC("com.mysql.jdbc.Driver", "C:/JDBC/mysql-connector-java-5.1.18-bin.jar", identifier.quote="`") conn &lt;- dbConnect(drv, "jdbc:mysql://server/schema?useOldAliasMetadataBehavior=true", "username", "password") query &lt;- "SELECT `a` AS `b` FROM table" result &lt;- dbGetQuery(conn, query) dbDisconnect(conn) </code></pre> <p>This ended up working for me! See more details, including caveats, in the <strong>Long Answer.</strong></p> <p><strong>Long Answer:</strong> I tried all sorts of stuff, including making views, changing queries, using JOIN statements, NOT using JOIN statements, using ORDER BY and GROUP BY statements, etc. I was never able to figure out why some of my queries were able to rename columns and others weren't.</p> <p>I contacted the package maintainer (Simon Urbanek.) Here is what he said:</p> <blockquote> <p>In the vast majority of cases this is an issue in the JBDC driver, because there is really not much RJDBC can do other than to call the driver.</p> </blockquote> <p>He then recommended that I make sure I had the most recent JDBC driver for MySQL. I did have the most recent version. However, it got me thinking "maybe it IS a bug with the JDBC driver." So, I searched Google for: <code>mysql jdbc driver bug alias</code>.</p> <p>The top result for this query was <a href="http://bugs.mysql.com/bug.php?id=33966">an entry at bugs.mysql.com</a>. Yev, using MySQL 5.1.22, says that when he upgraded from driver version 5.0.4 to 5.1.5, his column aliases stopped working. Asked if it was a bug.</p> <p>Sebastien replied, "No, it's not a bug! It's a documented change of behavior in all subsequent versions of the driver." and suggested using <code>?useOldAliasMetadataBehavior=true</code>, citing <a href="http://dev.mysql.com/doc/refman/5.1/en/connector-j-reference-configuration-properties.html">documentation for the JDBC driver</a>.</p> <p><strong>Caveat Lector:</strong> The documentation for the JDBC driver states that </p> <blockquote> <p>useColumnNamesInFindColumn is preferred over useOldAliasMetadataBehavior unless you need the specific behavior that it provides with respect to ResultSetMetadata.</p> </blockquote> <p>I haven't had the time to fully research what this means. In other words, I don't know what all of the ramifications are of using <code>useOldAliasMetadataBehavior=true</code> are. Use at your own risk. Does someone else have more information?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload