GithubHelp home page GithubHelp logo

Comments (11)

jimhester avatar jimhester commented on June 8, 2024 3

Perhaps try UTF-16? Clearly UTF-8 is not correct...

from odbc.

jimhester avatar jimhester commented on June 8, 2024 2

The single letter table names indicate that a mismatch between the encoding returned by the driver and what unixODBC is expecting.

In the amazon.redshiftodbc.ini file, located by default in /opt/amazon/redshift/lib/amazon.redshiftodbc.ini, you need to use the following settings

DriverManagerEncoding=UTF-8
ODBCInstLib=libodbcinst.so

You also may want to set a valid logPath

from odbc.

jimhester avatar jimhester commented on June 8, 2024

The amazon instructions you mention seem to be using iODBC, not unixODBC, perhaps that is part of the issue. The configuration instructions also mention modifying your LD_LIBRARY_PATH to ensure the driver libraries are loaded properly. You should ensure this is the case, particularly if you are starting R from somewhere other than the command line (like the RStudio IDE).

Also I would suggest using exactly the same strings in the manual configuration as in your odbc.ini, the default strings will likely not work for redshift.

A successful connection with isql should mean that odbc should also work, it is difficult to diagnose the issue without having a redshift instance to test against.

from odbc.

kylelundstedt avatar kylelundstedt commented on June 8, 2024

Thanks for the quick reply, @jimhester. I made progress by substituting in the actual path to the Amazon Redshift driver for the driver parameter. The good news is that the connection succeeds.

However, I get bogus answers when I use the odbc functions. I do have multiple schemas in the mortgage database; per issue #18, is there a workaround to use schema names in the odbc functions?

> library(DBI); library(ggplot2)
> con <- dbConnect(
+   odbc::odbc(),
+   driver = "/opt/amazon/redshift/lib/libamazonredshiftodbc.dylib",
+   servername = "mortgage.shared-vault.com", database = "mortgage",
+   UserName = "xxx", Password = "yyy", port = 5439
+ )
> dbListTables(con)
 [1] "c" "c" "d" "d" "g" "g" "l" "l" "l" "p" "a" "a" "c" "d" "e"
[16] "e" "h" "h" "l" "l" "l" "o" "p" "p" "p" "r" "s" "c" "f" "c"
[31] "i" "l" "l" "q" "s" "h" "h" "f" "p" "s" "s" "t" "l" "l" "s"
[46] "v" "i" "i" "i" "i" "i" "m" "m" "m" "m" "m" "z" "c" "l" "c"
[61] "c" "d" "d" "d" "g" "l" "l" "l" "l" "a" "f" "h" "h" "h" "h"
[76] "h" "h" "p" "p"
> dbListTables(con, table_name = "f%")
[1] "f" "f" "f"
> mpg_table <- dbWriteTable(con, "mpg", mpg)
Error in new_result(connection@ptr, statement) : 
  nanodbc.cpp:1587: 42501: [Amazon][Amazon Redshift] (30) Error occurred while trying to execute a query: [SQLState 42501] ERROR:  permission denied for schema cfpb_hmda

from odbc.

kylelundstedt avatar kylelundstedt commented on June 8, 2024

Hmm. I edited /opt/amazon/redshift/lib/amazon.redshiftodbc.ini.

[Driver]
## - Note that this default DriverManagerEncoding of UTF-32 is for iODBC.
# DriverManagerEncoding=UTF-32
DriverManagerEncoding=UTF-8
ErrorMessagesPath=/opt/amazon/redshift/ErrorMessages
LogPath=[LogPath]
SwapFilePath=/tmp

#   iODBC
# ODBCInstLib=libiodbcinst.dylib

ODBCInstLib=libodbcinst.so

I then got this output. 😄 Any ideas?

> dbListTables(con)
 [1] "畣楳彰楬歮"                    
 [2] "畣楳彰楬歮慟汬损獵灩"        
...

from odbc.

kylelundstedt avatar kylelundstedt commented on June 8, 2024

UTF-16 worked like a charm; awesome!!!

If I need to read or write to a specific schema, is that possible?

from odbc.

jimhester avatar jimhester commented on June 8, 2024

I need to look into schema support a bit more I think, but you can always fall back to writing the SQL by hand if needed and passing it to dbGetQuery().

from odbc.

kylelundstedt avatar kylelundstedt commented on June 8, 2024

Sounds good; thanks for all your help!

from odbc.

ftoresh avatar ftoresh commented on June 8, 2024

I have the same issue with Athena. Any idea?

from odbc.

 avatar commented on June 8, 2024

I have the same issue with Athena. Any idea?
Perhaps try UTF-16 (as jimhester has recommended)

from odbc.

ftoresh avatar ftoresh commented on June 8, 2024

I have the same issue with Athena. Any idea?
Perhaps try UTF-16 (as jimhester has recommended)

Indeed it worked!

from odbc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.