Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dbplyr::in_schema case sensitive

The function dbplyr::in_schema() can not connect to tables with uppercase letters.

When I create a table in PostgreSQL.

CREATE TABLE public."OCLOC"
(
  cod_ocloc double precision NOT NULL,
  lab_ocloc character varying(255),
  CONSTRAINT pk_ocloc PRIMARY KEY (cod_ocloc)
);

INSERT INTO public."OCLOC"(
            cod_ocloc, lab_ocloc)
    VALUES (1, 'example');

Then I try to connect to the table using in_schema from R:

 con <- DBI::dbConnect(RPostgreSQL::PostgreSQL(), 
                  dbname = 'dbname', 
                  user = 'user', 
                  host = 'host', 
                  password = 'password')

 tbl(con, dbplyr::in_schema('public','OCLOC'))

Warns about the following error

Error in postgresqlExecStatement(conn, statement, ...) : 
  RS-DBI driver: (could not Retrieve the result : ERROR:  no existe la relación «public.ocloc»
LINE 1: SELECT * FROM public.OCLOC AS "zzz3" WHERE 0=1
                  ^
)

But when I try without in_schema connection works:

tbl(con, 'OCLOC')

Looks like a case-insensitive problem, This generates a problem when I use database with other schemas besides the public and there are table names with capital letters.

like image 976
Diego Avatar asked Jul 20 '17 23:07

Diego


People also ask

How do I access non-default schemata in dplyr?

For analyses using dplyr, the in_schema () function should cover most of the cases when the non-default schema needs to be accessed. The following ODBC connection opens a session with the datawarehouse database: The database contains several schemata. The default schema is dbo.

How are schema and table pointers passed in dplyr piped code?

The schema and table are passed as quoted names: For interactive use, we would avoid using the tbl () command at the top of every dplyr piped code set. So it is better to load the table pointer into a variable:

When to use in_schema () in dplyr?

This is especially true for Data warehouses. It is rare when the default schema is going to have all of the data needed for an analysis. For analyses using dplyr, the in_schema () function should cover most of the cases when the non-default schema needs to be accessed.

What backend does dbplyr use?

In this vignette, we’re going to use the RSQLite backend which is automatically installed when you install dbplyr. SQLite is a great way to get started with databases because it’s completely embedded inside an R package. Unlike most other systems, you don’t need to setup a separate database server.


1 Answers

I have found the solution as follows: adding "" inside ''

tbl(con, '"OCLOC"')
like image 112
Diego Avatar answered Oct 17 '22 20:10

Diego