dongshuobei1037 2017-04-15 20:21
浏览 239

Postgres copy命令将zip文件加载到数据库中

I have a program that produces zip files and I save these temporarily in a directory like this:

  1.zip
  2.zip
  3.zip
  ...

I did a PHP program to load each of these files into a Postgres database but I need to do this with the command Postgres "copy" (because probably is faster)

I searched but I could not find the answer

So my table is like this:

  CREATE TABLE files (
  id int,
  file bytea,
  primary key (id));

So each file name is the "id" column and each zip file will be in "file" field

So how can i do this with a copy command?

Thank you all!

  • 写回答

1条回答 默认 最新

  • dongshi4773 2017-04-16 01:26
    关注

    COPY ... WITH BINARY has some limitation on the supported binary format and I'm not sure it works with zip files. If you're open to INSERT, I would suggest using pg_read_file, like:

    INSERT INTO files VALUES
    (1, pg_read_file('/path/to/1.zip')::bytea),
    (2, pg_read_file('/path/to/2.zip')::bytea),
    ...
    ;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 vscode问题请教
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM