SQLite 3 CSV 导入到表

发布于 2025-01-06 20:12:04 字数 564 浏览 0 评论 0原文

我将此作为开始的资源 - http://www.pantz.org /software/sqlite/sqlite_commands_and_general_usage.html

目前我正在使用内置的 SQLite 数据库创建一个 AIR 程序。在进行 SQL 查询方面,我可以说是一个十足的菜鸟。

表列类型

我有一个相当大的 Excel 文件(14K 行),我已将其导出到 CSV 文件。它有 65 列不同的数据类型(主要是整数、浮点数和短字符串,可能还有一些布尔值)。我不知道正确的导入形式以保留列结构,也不知道每个数据库列选择的最佳数据格式。我可以对此使用一些意见。

表创建实用程序

是否有一个实用程序可以读取 XLS 文件并根据列标题生成快速查询语句以减轻手动查询的痛苦?我看到了这篇文章,但它似乎面向预先存在的 CSV 文件,并使用了 python(我也是菜鸟)

提前感谢您的宝贵时间。 J

I am using this as a resource to get me started - http://www.pantz.org/software/sqlite/sqlite_commands_and_general_usage.html

Currently I am working on creating an AIR program making use of the built in SQLite database. I could be considered a complete noob in making SQL queries.

table column types

I have a rather large excel file (14K rows) that I have exported to a CSV file. It has 65 columns of varying data types (mostly ints, floats and short strings, MAYBE a few bools). I have no idea about the proper form of importing so as to preserve the column structure nor do I know the best data formats to choose per db column. I could use some input on this.

table creation utils

Is there a util that can read an XLS file and based on the column headers, generate a quick query statement to ease the pain of making the query manually? I saw this post but it seems geared towards a preexisting CSV file and makes use of python (something I am also a noob at)

Thank you in advance for your time.
J

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋意浓 2025-01-13 20:12:04

SQLite3 的列类型基本上可以归结为:

  • TEXT
  • NUMERIC (REAL, FLOAT)
  • INTEGER (各种长度的整数;但 INT 通常会这样做)
  • BLOB (二进制对象)

通常在 CSV 文件中你会遇到字符串 (TEXT)、十进制数字 ( FLOAT) 和整数 (INT)。如果性能并不重要,那么这些几乎是您需要的唯一三种列类型。 (CHAR(80) 在磁盘上比 TEXT 小,但对于几千行来说,这并不是什么大问题。)

就将数据放入列而言,SQLite3 使用类型强制将输入数据类型转换为列类型(只要转换有意义)。因此,您所要做的就是指定正确的列类型,SQLite 会以正确的方式存储它。

例如,数字 -1230.00、字符串 "-1230.00" 和字符串 "-1.23e3" 都将强制转换为数字 1230当存储在 FLOAT 列中时。

请注意,如果 SQLite3 无法应用有意义的类型转换,它将仅存储原始数据,而根本不会尝试对其进行转换。 SQLite3 非常乐意将 "Hello World!" 插入到 FLOAT 列中。这通常是一件坏事。

请参阅 有关列类型和转换的 SQLite3 文档,了解 gem,例如:

类型亲和力

为了最大化SQLite与其他数据库的兼容性
引擎,SQLite 支持列上的“类型关联”概念。
列的类型关联是存储数据的推荐类型
在那一栏里。这里重要的想法是类型是
推荐,非必需。任何列仍然可以存储任何类型的
数据。只是有些专栏如果有选择的话会更喜欢
使用一种存储类别而不是另一种。首选存储类别
列称为其“亲和力”。

SQLite3's column types basically boil down to:

  • TEXT
  • NUMERIC (REAL, FLOAT)
  • INTEGER (the various lengths of integer; but INT will normally do)
  • BLOB (binary objects)

Generally in a CSV file you will encounter strings (TEXT), decimal numbers (FLOAT), and integers (INT). If performance isn't critical, those are pretty much the only three column types you need. (CHAR(80) is smaller on disk than TEXT but for a few thousand rows it's not so much of an issue.)

As far as putting data into the columns is concerned, SQLite3 uses type coercion to convert the input data type to the column type whereever the conversion makes sense. So all you have to do is specify the correct column type, and SQLite will take care of storing it in the correct way.

For example the number -1230.00, the string "-1230.00", and the string "-1.23e3" will all coerce to the number 1230 when stored in a FLOAT column.

Note that if SQLite3 can't apply a meaningful type conversion, it will just store the original data without attempting to convert it at all. SQLite3 is quite happy to insert "Hello World!" into a FLOAT column. This is usually a Bad Thing.

See the SQLite3 documentation on column types and conversion for gems such as:

Type Affinity

In order to maximize compatibility between SQLite and other database
engines, SQLite supports the concept of "type affinity" on columns.
The type affinity of a column is the recommended type for data stored
in that column. The important idea here is that the type is
recommended, not required. Any column can still store any type of
data. It is just that some columns, given the choice, will prefer to
use one storage class over another. The preferred storage class for a
column is called its "affinity".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文