zoukankan      html  css  js  c++  java
  • postgresql存储二进制大数据文件

    如果想把整个文件或图片存储在数据表的一个字段内,该字段可以选择二进制类型,然后将文件按二进制存储起来,文本文件也可以存在text字段内。

    示例如下:

    二进制类型bytea的操作(在最大值内,有内存限制)

    1、 创建表

    Create table byteatable(id int,obj bytea);

    2、 将文件放到coordinator目录下/mnt/postgresql/coord

    通过pg_read_binary_file()函数,插入一张图片- 目录:/mnt/postgresql/coord/1.jpg

    postgresql =# Insert into byteatablevalues(256,pg_read_binary_file('1.jpg'));
    INSERT 0 1 
    postgresql =# Insert into byteatablevalues(256,pg_read_binary_file('weibo.txt'));
    INSERT 0 1

    3、 也可以调用pg_read _file()将一个文本文件存储在一个text字段内

    postgresql=#ALTER TABLE byteatable ADD COLUMN body text;
    ALTER TABLE
    postgresql=#Insert into  byteatable values(256,pg_read_binary_file('weibo.txt'),
    pg_read_file('weibo.txt'));
    INSERT 0 1
    postgresql =# select body from byteatable whereid='256';

    注意:函数pg_read_binary_file()pg_read_file()中的路径必须是相对路径,默认路径是coordinator目录下,并且必须在coordinator目录下或者coordinator目录的子目录下。

    Name

    Return Type

    Description

    pg_read_file(filename text [, offset bigint, length bigint])

    text

    Return the contents of a text file

    pg_read_binary_file(filename text [, offset bigint, length bigint])

    bytea

    Return the contents of a file

  • 相关阅读:
    洛谷 P2896 [USACO08FEB]Eating Together S
    洛谷 P1564 膜拜
    洛谷 P1684 考验
    洛谷 P2031 脑力达人之分割字串
    洛谷 P2725 邮票 Stamps
    洛谷 P2904 [USACO08MAR]跨河River Crossing
    洛谷 P1929 迷之阶梯
    洛谷 P2375 [NOI2014]动物园
    谷歌浏览器禁止表单自动填充
    SQL数据同步之发布订阅
  • 原文地址:https://www.cnblogs.com/xiaodf/p/5027195.html
Copyright © 2011-2022 走看看