David Bijoyan
David Bijoyan

Reputation: 117

How to write properly table name in dbGetQuery function?

I have an issue of specifying table name in dbGetQuery function.

The command

data1 <- dbGetQuery(con, "select * from bank_schema.capital")

works well.

But the command

data1 <- dbGetQuery(con, "select * from bank_schema.135_ratios")

throws an error.

Where con is connection object to postgreSQL database.

Please, help me to find way out.

Thanks in advance.

Upvotes: 1

Views: 236

Answers (2)

Lukasz Szozda
Lukasz Szozda

Reputation: 175686

You need to quote identifier with ":

data1 <- dbGetQuery(con, "select * from bank_schema.\"135_ratios\"")

Upvotes: 1

GMB
GMB

Reputation: 222452

Postgres by default does not support table names that start with digits (other RDBMS have the same limitation). You would need to quote the table name. Consider:

data1 <- dbGetQuery(con, 'select * from bank_schema."135_ratios"')

Or:

data1 <- dbGetQuery(con, "select * from bank_schema.\"135_ratios\"")

But better yet, it would be simpler to rename the table to something more standard (ie that does not start with a digit), for example ratios_135.

Upvotes: 2

Related Questions