简体   繁体   English

如何将数据从 postgres 数据库导入到 android sqlite

[英]how to import data from postgres database to android sqlite

I have a Postgres database server and I need to download the table records from postgres to tablet android (sqlite database).我有一个 Postgres 数据库服务器,我需要将表记录从 postgres 下载到平板电脑 android(sqlite 数据库)。 Is there a feature in Android to do this? Android 中是否有一个功能可以做到这一点?

Example: There is a customer table in postgres and i need to import this table to sqlite in android.示例:postgres 中有一个客户表,我需要将此表导入到 android 中的 sqlite。

Any tips are welcome.欢迎任何提示。

Best regards.最好的祝福。

This can be done by dumbing database in sql file from postgres and importing it to sqlite. 这可以通过将来自postgres的sql文件中的数据库哑巴并导入到sqlite中来完成。

Dump database in a sql file. 将数据库转储到sql文件中。

pg_dump dbname > outfile.sql

Ref: http://www.postgresql.org/docs/9.1/static/backup-dump.html 参考: http : //www.postgresql.org/docs/9.1/static/backup-dump.html

Import database from sql dump file 从sql转储文件导入数据库

sqlite> .read outfile.sql

Ref: https://www.sqlite.org/cli.html 参考: https : //www.sqlite.org/cli.html

You can dump specific table in postgres using following command: 您可以使用以下命令在postgres中转储特定表:

pg_dump  --table=table dbname > outfile.sql

...also you should clean your dump file before conversion ...你也应该在转换前清理你的转储文件
to replace all true -> 't', false -> 'f'(but don't touch true and false in CREATE TABLE s)替换所有 true -> 't', false -> 'f'(但不要在CREATE TABLE s 中触摸 true 和 false)
remove all lines started with SET , SELECT , ALTER etc.删除所有以SETSELECTALTER等开头的行。
remove all mentions of SCHEMA .删除所有提及的SCHEMA and OWNEROWNER
(sqlite does not understand it) (sqlite看不懂)
there should stay only commands CREATE TABLE and your data应该只保留命令CREATE TABLE和您的数据
such as INSERT INTO例如插入
and check data types - SQLite does not understand BIG_INT (and not only him)并检查数据类型 - SQLite不了解BIG_INT (不仅是他)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM