PostgreSQL数据导入/导出实用程序

pgmerge的Python项目详细描述


pgmerge-PostgreSQL数据导入和合并实用程序

Build StatusPyPI version

此实用程序的主要目的是管理一组csv文件,这些文件与postgresql数据库中的表相对应。然后,这些csv文件中的每一个都可以被合并到它们的表中,这意味着将发生以下过程(也称为upsert操作):

  • 表中尚未存在主键的行将被导入。
  • 当主键已经存在时,行值将被更新。
  • 将忽略丢失或未更改的行。

然后,pgmerge还可以以导入所需的相同格式导出数据。

这些功能允许您在具有相同架构的数据库之间移动数据,以使它们保持最新和同步,尽管它不包括处理已删除的数据。

$ pgmerge --help
Usage: pgmerge [OPTIONS] COMMAND [ARGS]...

Merges data in CSV files into a Postgresql database.

Options:
--version  Show the version and exit.
--help     Show this message and exit.

Commands:
export  Export each table to a CSV file.
import  Import/merge each CSV file into a table.
inspect  Inspect database schema in various ways.

导入

$ pgmerge import --help
Usage: pgmerge import [OPTIONS] DIRECTORY [TABLES]...

Import/merge each CSV file into a table.

All CSV files need the same name as their matching table and have to be located
in the given directory. If one or more tables are specified then only they will
be used, otherwise all tables found will be selected.

Options:
-d, --dbname TEXT               Database name to connect to.  [required]
-h, --host TEXT                 Database server host or socket directory.
                                [default: localhost]
-p, --port TEXT                 Database server port.  [default: 5432]
-U, --username TEXT             Database user name.  [default: postgres]
-s, --schema TEXT               Database schema to use.  [default: public]
-w, --no-password               Never prompt for password (e.g. peer
                                authentication).
-W, --password TEXT             Database password (default is to prompt for
                                password or read config).
-L, --uri TEXT                  Connection URI can be used instead of specifying
                                parameters separately (also sets --no-password).
-f, --ignore-cycles             Don't stop import when cycles are detected in
                                schema (will still fail if there are cycles in
                                data)
-F, --disable-foreign-keys      Disable foreign key constraint checking during
                                import (necessary if you have cycles, but requires
                                superuser rights).
-c, --config PATH               Config file for customizing how tables are
                                imported/exported.
-i, --include-dependent-tables  When selecting specific tables, also include all
                                tables on which they depend due to foreign key
                                constraints.
--help                          Show this message and exit.

安装

WARNING: the reliability of this utility is not guaranteed and loss or corruption of data is always a possibility.

从pypi安装

在系统上安装Python 3后,您可以运行:

pip install pgmerge

(您的pip --version必须是9.0或更高版本)。要测试安装是否有效,请运行:

pgmerge --help

您可以随时使用以下命令卸载:

pip uninstall pgmerge

从github安装

直接从github安装最新代码:

pip install git+https://github.com/samuller/pgmerge

问题

如果您在安装和运行一个基于debian的linux时遇到问题,该linux使用Python 2作为其系统默认值,那么您可能需要运行:

sudo apt install libpq-dev python3-pip python3-setuptools
sudo -H pip3 install pgmerge

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java将信息存储到另一个类的数组中   java将视频帧添加到JTabbed窗格   java Wicket下拉选择只读   java/Servlets/ISO88591代替UTF8   Java AWS ElastiCache Redis连接超时   升级到Tomcat 7.0.54后java面临404错误   java Hashmap、wicket和计时器?   rust如何使用Java GraalVM在Java代码和嵌入式WASM代码之间传递字符串作为参数和返回值   在调整大小后,如何将java中图像的DPI从96更改为300?   远程文件的java下载统计信息   javascript如何在服务器上复制由jsPDF在web客户端生成的pdf?   java在没有读取权限的情况下从可扩展客户端读取数据   java如何从设备id生成IMIE   java为什么布局参数在Android编程中起作用?   java如何向服务器发送json   java中的数组和对象   java JSON未确定字符串错误