当前位置: 首页 > news >正文

【postgres】sqlite格式如何导入postgres数据库

step1 在ubuntu系统安装pgloader(centos系统难以直接通过yum安装,如果源码安装的话,会比较费劲)

step2,执行如下python脚本

from pathlib import Path
import subprocess

dataset_dir = Path('/app/sqlite_to_pg/chase-page/data/database/')

# 遍历目录获取所有文件路径
file_paths = [str(p.absolute()) for p in dataset_dir.rglob('*') if p.is_file()]

for fn in file_paths:
    # 创建或更新 a.load 文件内容
    load_file_content = f"""
LOAD DATABASE
    FROM sqlite://{fn}
    INTO pgsql://postgres@192.168.1.14:5432/tablegpt_test_chase


WITH include drop,  -- 在导入前删除已存在的表
     create tables, -- 自动创建目标表
     create indexes, -- 创建索引
     reset sequences  -- 重置序列

CAST
    type number to text,
    type time to text,
    type string to text;
    """

    # 写入 a.load 文件
    with open('a.load', 'w') as file:
        file.write(load_file_content)

    # 执行 pgloader 命令
    command = ['pgloader', 'a.load']

    try:
        result = subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
        print("Command executed successfully")
        print("Output:", result.stdout)
    except subprocess.CalledProcessError as e:
        print("An error occurred while executing the command:")
        print("Exit status:", e.returncode)
        print("Error output:", e.stderr)

http://www.lryc.cn/news/523220.html

相关文章:

  • 阀井可燃气体监测仪,开启地下管网安全新篇章-旭华智能
  • 《offer 来了:Java 面试核心知识点精讲 -- 原理篇》
  • 搭建一个基于Spring Boot的数码分享网站
  • K210视觉识别模块
  • JAVA:在IDEA引入本地jar包的方法(不读取maven目录jar包)
  • 存在重复元素(217)
  • 聊聊如何实现Android 放大镜效果
  • linux 安装mysql5.6
  • 【Vue3 入门到实战】3. ref 和 reactive区别和适用场景
  • edge浏览器恢复旧版滚动条
  • Flink(十):DataStream API (七) 状态
  • AWTK fscript 中的 输入/出流 扩展函数
  • C# OpenCvSharp 部署3D人脸重建3DDFA-V3
  • 【人工智能】:搭建本地AI服务——Ollama、LobeChat和Go语言的全方位实践指南
  • 数据结构——堆(介绍,堆的基本操作、堆排序)
  • Excel中函数ABS( )的用法
  • 【数据分析】02- A/B 测试:玩转假设检验、t 检验与卡方检验
  • Windows下的C++内存泄漏检测工具Visual Leak Detector (VLD)介绍及使用
  • [苍穹外卖] 1-项目介绍及环境搭建
  • 人物一致性训练测评数据集
  • AI的出现,是否能替代IT从业者?
  • 乘联会:1月汽车零售预计175万辆 环比暴跌33.6%
  • LLM - 大模型 ScallingLaws 的 CLM 和 MLM 中不同系数(PLM) 教程(2)
  • 开发神器之cursor
  • 使用 Ansys Motor-CAD 的自适应模板加速创新
  • RabbitMQ前置概念
  • http转化为https生成自签名证书
  • 《贪心算法:原理剖析与典型例题精解》
  • 【网络协议】【http】【https】RSA+AES-TLS1.2
  • 【数据库】MySQL数据库之约束与多表查询