SQLテーブルのカラム(フィールド?)タイプを取得するためのdplyr
(または他のパッケージ)コマンドはありますか?たとえば...dplyrを使用してSQLテーブルのカラムタイプを取得
library(RSQLite)
library(dplyr)
data(iris)
dat_sql <- src_sqlite("test.sqlite", create = TRUE)
copy_to(dat_sql, iris, name = "iris_df")
iris_tbl <- tbl(dat_sql, "iris_df")
iris_tbl
# Source: query [?? x 5]
# Database: sqlite 3.8.6 [test.sqlite]
#
# Sepal.Length Sepal.Width Petal.Length Petal.Width Species
# <dbl> <dbl> <dbl> <dbl> <chr>
# 1 5.1 3.5 1.4 0.2 setosa
# 2 4.9 3.0 1.4 0.2 setosa
# 3 4.7 3.2 1.3 0.2 setosa
# 4 4.6 3.1 1.5 0.2 setosa
# 5 5.0 3.6 1.4 0.2 setosa
# 6 5.4 3.9 1.7 0.4 setosa
# 7 4.6 3.4 1.4 0.3 setosa
# 8 5.0 3.4 1.5 0.2 setosa
# 9 4.4 2.9 1.4 0.2 setosa
# 10 4.9 3.1 1.5 0.1 setosa
# # ... with more rows
は、私が最初の4列は、タイプdbl
のものであり、最後はchr
であることを私に言うだろう、そのコマンドに興味がある(またはより良いまだ、Rタイプnumeric
とcharacter
) 実際にはありませんcollect
メモリ内のデータ。印刷されているので、これを行う方法がなければなりません、そうですか?私は無駄にstr
を試してみました:列はページ、 をダウンを実行し、データは全体の実行されます。
str(iris_tbl)
# List of 2
# $ src:List of 2
# ..$ con :Formal class 'SQLiteConnection' [package "RSQLite"] with 5 slots
# .. .. [email protected] Id :<externalptr>
# .. .. [email protected] dbname : chr "test.sqlite"
# .. .. [email protected] loadable.extensions: logi TRUE
# .. .. [email protected] flags : int 6
# .. .. [email protected] vfs : chr ""
# ..$ path: chr "test.sqlite"
# ..- attr(*, "class")= chr [1:3] "src_sqlite" "src_sql" "src"
# $ ops:List of 3
# ..$ src :List of 2
# .. ..$ con :Formal class 'SQLiteConnection' [package "RSQLite"] with 5 slots
# .. .. .. [email protected] Id :<externalptr>
# .. .. .. [email protected] dbname : chr "test.sqlite"
# .. .. .. [email protected] loadable.extensions: logi TRUE
# .. .. .. [email protected] flags : int 6
# .. .. .. [email protected] vfs : chr ""
# .. ..$ path: chr "test.sqlite"
# .. ..- attr(*, "class")= chr [1:3] "src_sqlite" "src_sql" "src"
# ..$ x :Classes 'ident', 'sql', 'character' chr "iris_df"
# ..$ vars: chr [1:5] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" ...
# ..- attr(*, "class")= chr [1:3] "op_base_remote" "op_base" "op"
# - attr(*, "class")= chr [1:4] "tbl_sqlite" "tbl_sql" "tbl_lazy" "tbl"
# NULL
満足できないと感じますが、機能していることを否定できません!大きなデータベースの 'head'(または' tail')ステートメントにオーバーヘッドがかかっているかどうか知っていますか?私はしばしば数百万行のオーダーのデータを扱います。 –
また、 'type_sum'に+1がありました。間違いなく、以前はそのコマンドに気付かなかったのです! –
ソースコードで判断すると、SQL dbsのように見えます。 'head(...、n)'は 'n'行の' limit'を持つ 'select'文に変換されます。 –