Reputation:
I want to connect and query a bigquery database through the dplyr package in R. I know I can list all the tables in the database as follows:
library(dplyr)
con <- DBI::dbConnect(dbi_driver(),
project = "publicdata",
dataset = "samples",
billing = "887175176791"
)
DBI::dbListTables(con)
[1] "github_nested" "github_timeline" "gsod" "natality" "shakespeare" "trigrams"
[7] "wikipedia"
But how do I list the column names for a particular table? I tried the following,
DBI::dbListFields(con, "gsod")
but I received the following error
Error: Not yet implemented: dbListFields(Connection, character)
Upvotes: 1
Views: 539
Reputation: 25454
For now, you can use something like
tbl <- DBI::dbGetQuery("SELECT * FROM gsod", n = 1) # or n = 0
names(tbl)
This will select just one (or zero) rows from the table as a data frame, with column names taken from the remote table.
Upvotes: 0