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.
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.
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:
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.
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.
I have found the solution as follows: adding ""
inside ''
tbl(con, '"OCLOC"')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With