Har*_*_OK 5 sql postgresql blob
我知道可以使用以下命令从 PostgreSQL 脚本插入大对象lo_import():
INSERT INTO image (name, raster)
VALUES ('beautiful image', lo_import('/etc/motd'));
Run Code Online (Sandbox Code Playgroud)
问题是,我试图在一个紧密锁定的服务器上执行一个脚本,所以我无法将文件上传到它。是否可以在不依赖外部文件的情况下将常量字符串插入到大对象中?
如果该值小于 1GB,则可以执行以下操作:
INSERT INTO image (name, raster)
VALUES ('beautiful image', lo_from_bytea(0,$1));
Run Code Online (Sandbox Code Playgroud)
该bytea类型是有点讨厌。您可能不得不求助于特定于驱动程序的恶作剧,以使驱动程序/客户端库理解 $1 的类型为bytea。例如,在 Perl 的 DBD::Pg 中,您必须准备语句,然后执行以下操作:
$insert->bind_param(1, $blob, { pg_type => PG_BYTEA });
Run Code Online (Sandbox Code Playgroud)