Search code examples
postgresqlerlang

How to connect to PostgreSQL with epgsql (Erlang)?


I want to run a simple PostgreSQL query with Erlang and epgsql similar to Erlang and PostgreSQL. I am getting

** 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"}]}}

on

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

My PostgreSQL instance works fine and I can add a table to my database or run simple queries. But I need to do it with epgsql. And furthermore, I can't read error message, this is what I can see:

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

Solution

  • I installed egpsql, did a direct test, and confirmed that the second parameter for connect is the username and the third is the password:

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