简体   繁体   中英

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). Is there a feature in Android to do this?

Example: There is a customer table in postgres and i need to import this table to sqlite in android.

Any tips are welcome.

Best regards.

This can be done by dumbing database in sql file from postgres and importing it to sqlite.

Dump database in a sql file.

pg_dump dbname > outfile.sql

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

Import database from sql dump file

sqlite> .read outfile.sql

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

You can dump specific table in postgres using following command:

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)
remove all lines started with SET , SELECT , ALTER etc.
remove all mentions of SCHEMA . and OWNER
(sqlite does not understand it)
there should stay only commands CREATE TABLE and your data
such as INSERT INTO
and check data types - SQLite does not understand BIG_INT (and not only him)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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