CREATE OR REPLACE FUNCTION db_to_csv(path text) RETURNS voID AS$BODY$declare tables RECORD; statement TEXT;begin FOR tables IN SELECT (table_schema || '.' || table_name) AS schema_table FROM information_schema.tables t INNER JOIN information_schema.schemata s ON s.schema_name = t.table_schema WHERE t.table_schema NOT IN ('pg_catalog','information_schema','configuration') ORDER BY schema_table LOOP statement := 'copY ' || tables.schema_table || ' TO ''' || path || '/' || tables.schema_table || '.csv' ||''' DEliMITER '';'' CSV header'; EXECUTE statement; END LOOP; return; end;$BODY$ LANGUAGE plpgsql VolATILE COST 100;ALTER FUNCTION db_to_csv(text) OWNER TO postgres;
但当我调用此函数时,我无法打开文件“/home/user/documents/public.tablename.csv”进行写入:权限被拒绝
我曾尝试使用复制单个表
copY activitIEs TO '/home/user/documents/foldername/conversions/tablename.csv' DEliMITER ',' CSV header;
它给了我以下错误
ERROR: Could not open file "/home/user/documents/foldername/conversions/tablename.csv" for writing: Permission denIEd********** Error ********** ERROR: Could not open file "/home/user/documents/foldername/conversions/tablename.csv" for writing: Permission denIEdsql state: 42501
任何建议如何解决这个问题.
解决方法 创建一个每个用户都有权访问的文件夹.然后在那里的文件上运行copY命令. copY仅适用于postgres用户有权访问的目录sudo mkdir /media/exportsudo chmod 777 /media/exportcopY activitIEs TO '/media/export/activitIEs.csv' DEliMITER ',' CSV header;总结
以上是内存溢出为你收集整理的database – 将postgres表导出为csv错误全部内容,希望文章能够帮你解决database – 将postgres表导出为csv错误所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)