且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用文件内容更新psql中的单个字段?

更新时间:2023-11-09 20:36:34

经过大量搜索,我发现了此答案,它没有直接讨论阅读问题文件,但为我的古代 Postgres 提供了必要的成分。

After much searching, I discovered this answer, which does not directly discuss the problem of reading files, but gave me the necessary ingredient to make this work for my ancient Postgres.

\set contentFill `cat Foo.txt`
\set quoted_contentFill '\'' :contentFill '\''
UPDATE bodycontent SET body=:quoted_contentFill WHERE contentid=12943363; 

自然,如果 Foo中有未转义的引号,则此操作将失败。 txt ,但是我可以轻松地进行预处理以确保没有任何内容。

Naturally, this will fail if there are un-escaped quotes inside Foo.txt, but I can easily preprocess to ensure there are none.