我正在尝试在postgresql(pg commander)中编写一个更新sql语句,它将更新用户个人资料图像列
我试过这个:
update mytable set avatarImg = pg_read_file('/Users/myUser/profile.png')::bytea where userid=5;
得到ERROR: absolute path not allowed
答案 0 :(得分:1)
答案 1 :(得分:0)
(阐述理查德的正确但简洁的答案;他应该被标记为正确):
<VirtualHost *:443>
ServerName domain.com
DocumentRoot rootPath
SSLENGINE on
SSLCertificatekeyFile keyPath
SSLCertificateFile certPath
SSLCertificateChainFile chainPath
</VirtualHost>
<VirtualHost *:80>
RewriteEngine On
RewriteRule ^ https://domain.com%{REQUEST_URI} [R=301,L]
</VirtualHost>
<VirtualHost *:443>
DocumentRoot rootPath
SSLENGINE on
SSLCertificatekeyFile keyPath
SSLCertificateFile certPath
SSLCertificateChainFile chainPath
RewriteEngine On
RewriteRule ^ https://domain.com%{REQUEST_URI} [R=301,L]
</VirtualHost>
实际上仅用作管理工具,并且符合the manual:
表9-72中显示的功能提供对托管服务器的计算机上的文件的本机访问。只能访问数据库集群目录和log_directory中的文件。
即使该限制不适用,使用pg_read_file
也是不正确的;您必须使用pg_read_file
。您不能只是阅读pg_read_binary_file
并像这样投射到text
。
路径限制意味着您必须使用客户端应用程序读取文件,正如Richard所说。从客户端读取文件,在SQL中将其设置为bytea
放置参数,然后发送查询。
或者,您可以使用bytea
作为二进制大对象读取服务器端文件,然后将其读取为lo_import
并删除二进制大对象。
答案 2 :(得分:0)
pg_read_file仅可以从数据目录路径读取文件,如果您想知道您的数据目录路径使用的话:
SHOW data_directory;
例如,它将显示
/var/lib/postgresql/data
将文件复制到上述目录。 之后,您只能在查询中使用文件名。
UPDATE student_card SET student_image = pg_read_file('up.jpg')::bytea;
或者可以使用pg_read_binary_file函数。
UPDATE student_card SET student_image = pg_read_binary_file('up.jpg')::bytea;