如何在 Windows 上的 postgresql 9.1 中安装 pgcrypto?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8000740/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I install pgcrypto in postgresql 9.1 on Windows?
提问by Dean Schulze
The web page for Postgresql says that pgcrypto is included in the download for Postgresql 9.1. There is no pgcrypto.sql file, however. If I look in the share\extension directory there are 3 files:
Postgresql 的网页说 pgcrypto 包含在 Postgresql 9.1 的下载中。但是,没有 pgcrypto.sql 文件。如果我查看 share\extension 目录,有 3 个文件:
pgcrypto--1.0.sql pgcrypto--unpackaged--1.0.sql pgcrypto.control
pgcrypto--1.0.sql pgcrypto--unpackaged--1.0.sql pgcrypto.control
If I try to install with
如果我尝试安装
\i pgcrypto--1.0.sql
\i pgcrypto--1.0.sql
I get a bunch of errors like this:
我收到一堆这样的错误:
psql:pgcrypto--1.0.sql:194: ERROR: could not access file "MODULE_PATHNAME": No such file or directory
Maybe the files in share\extension were meant to be called by the share\contrib\pgcrypto.sql file (which doesn't exist).
也许 share\extension 中的文件是由 share\contrib\pgcrypto.sql 文件(不存在)调用的。
On linux on Postgresql 8.4 I have to install the contrib package to get pgcrypto.sql. Is there another package I have to install on Windows for Postgresql 9.1?
在 linux 上的 Postgresql 8.4 我必须安装 contrib 包才能获得 pgcrypto.sql。我必须在 Windows 上为 Postgresql 9.1 安装另一个包吗?
Thanks.
谢谢。
回答by Milen A. Radev
In v9.1 the way to install extra modules was changed, those are now called EXTENSIONS and are installed with a special SQL statement CREATE EXTENSION.
在 v9.1 中,安装额外模块的方式发生了变化,这些模块现在称为 EXTENSIONS 并使用特殊的 SQL 语句CREATE EXTENSION 安装。
回答by liyuhui
1.add the extensions: create extension pgcrypto
1.添加扩展:创建扩展pgcrypto
2.check the extensions: select * from pg_available_extensions
2.检查扩展名:select * from pg_available_extensions
3.use the extensions: select '{SHA}'||encode(digest('test', 'sha1'), 'base64');
3.使用扩展:选择'{SHA}'||encode(digest('test', 'sha1'), 'base64');
回答by David S
I was trying to convert a MySQL script that contained their SHA1 function. After finally doing the "create extension pgcrypto" command, then the example in the PostgreSQL documentation worked perfectly (at least all of the values I've tried so far).
我试图转换包含其 SHA1 函数的 MySQL 脚本。在最终执行“创建扩展 pgcrypto”命令后,PostgreSQL 文档中的示例运行良好(至少我尝试过的所有值都是如此)。
Here is the SHA1 function:
这是 SHA1 函数:
CREATE OR REPLACE FUNCTION sha1(bytea) returns text AS $$
SELECT encode(digest(, 'sha1'), 'hex')
$$ LANGUAGE SQL STRICT IMMUTABLE;
It should be noted that I did all of this on PostgreSQL 9.1 with the PgAdminIII tool and on 64-bit Windows 7.
应该注意的是,我使用 PgAdminIII 工具在 PostgreSQL 9.1 和 64 位 Windows 7 上完成了所有这些。
回答by hermeslm
If you need use some extension, the way is for example for pgcrypto: "CREATE EXTENSION pgcrypto" from a window query, but is very important to said that this script must be executed in the DB that you need to use this extension, after having finished the script to verify that it is installed, check in pgAdmin over your DB the extensions seccion.
如果你需要使用一些扩展,例如 pgcrypto: "CREATE EXTENSION pgcrypto" 来自窗口查询,但很重要的是说这个脚本必须在你需要使用这个扩展的数据库中执行,之后完成脚本以验证它是否已安装,在 pgAdmin 中检查您的数据库的扩展部分。
I hope this help.
我希望这会有所帮助。