PostgreSQL:在不依赖外部文件的情况下从 SQL 脚本在大对象中插入字符串
PostgreSQL: insert string in a large object from an SQL script without relying on an external file
我知道可以使用 lo_import()
:
从 PostgreSQL 脚本插入一个大对象
INSERT INTO image (name, raster)
VALUES ('beautiful image', lo_import('/etc/motd'));
问题是,我正试图在紧紧锁定的服务器上执行脚本,所以我无法向其上传文件。是否可以在不依赖外部文件的情况下将常量字符串插入到大对象中?
如果该值小于 1GB,您可以这样做:
INSERT INTO image (name, raster)
VALUES ('beautiful image', lo_from_bytea(0,));
bytea
类型有点烦人。您可能不得不求助于特定于驱动程序的恶作剧,以使 driver/client 库理解 $1 的类型为 bytea
。例如,在 Perl 的 DBD::Pg 中,您必须准备语句然后执行以下操作:
$insert->bind_param(1, $blob, { pg_type => PG_BYTEA });
我知道可以使用 lo_import()
:
INSERT INTO image (name, raster)
VALUES ('beautiful image', lo_import('/etc/motd'));
问题是,我正试图在紧紧锁定的服务器上执行脚本,所以我无法向其上传文件。是否可以在不依赖外部文件的情况下将常量字符串插入到大对象中?
如果该值小于 1GB,您可以这样做:
INSERT INTO image (name, raster)
VALUES ('beautiful image', lo_from_bytea(0,));
bytea
类型有点烦人。您可能不得不求助于特定于驱动程序的恶作剧,以使 driver/client 库理解 $1 的类型为 bytea
。例如,在 Perl 的 DBD::Pg 中,您必须准备语句然后执行以下操作:
$insert->bind_param(1, $blob, { pg_type => PG_BYTEA });