通过pgsql(Erlang)连接到PostgreSQL

时间:2013-03-31 17:54:38

标签: postgresql erlang

我想用Erlang and PostgreSQL中的Erlang和epgsql执行简单的PostgreSQL查询。但是wnen发出以下代码:

{ok, C} = pgsql:connect("localhost", 
                        "postgres", 
                        "nevermind", 
                        [{database, "postgres"}]).

我收到此错误:

** exception error: no match of right hand side value 
                {error,
                    {authentication,
                        [{severity,'Ð\222Ð\220Ð\226Ð\235Ð\236'},
                         {code,"28000"},
                         {message,
                             [208,191,208,190,208,187,209,140,208,183,208,
                              190,208,178,208,176,209,130,208,181|...]},
                         {file,"auth.c"},
                         {line,302},
                         {routine,"auth_failed"}]}}

PostgreSQL可以工作,我可以将表添加到我的数据库中或进行简单的查询。但是我需要用Erlang来做。更重要的是,我无法在列表中读取完整的错误消息:

[208,191,208,190,208,187,209,140,208,183,208,190,208,178,208,176,209,130,208,181|...]

1 个答案:

答案 0 :(得分:1)

我安装了egpsql,进行了直接测试,并确认connect的第二个参数是用户名,第三个是密码:

{ok, C} = pgsql:connect("localhost", "username", "password", [{database, "db_name"}]).
{ok, Columns, Rows} = pgsql:squery(C, "select * from myschema.mytable").