Skip to content

equery with array input doesn't work with select ... where ... in ($1) #34

@dantswain

Description

@dantswain

The following query works:

pgsql:equery(C, "select name from servers where id = any ($1)", [[1, 2, 4]]).

whereas this one does not:

pgsql:equery(C, "select name from servers where id in ($1)", [[1, 2, 4]]).

The only difference is the use of id in ($1) vs. id = any ($1). The second version results in an error:

=ERROR REPORT==== 6-Aug-2013::10:04:58 ===
** State machine <0.1053.0> terminating
** Last message in was {'$gen_sync_event',
                           {<0.1051.0>,#Ref<0.0.0.199>},
                           {equery,
                               {statement,[],
                                   [{column,<<"name">>,varchar,-1,54,1}],
                                   [int4]},
                               [{int4,[1,2,4]}]}}
** When State == ready
**      Data  == {state,undefined,<0.1054.0>,5000,
                        [{<<"application_name">>,<<>>},
                         {<<"client_encoding">>,<<"UTF8">>},
                         {<<"DateStyle">>,<<"ISO, MDY">>},
                         {<<"integer_datetimes">>,<<"on">>},
                         {<<"IntervalStyle">>,<<"postgres">>},
                         {<<"is_superuser">>,<<"on">>},
                         {<<"server_encoding">>,<<"UTF8">>},
                         {<<"server_version">>,<<"9.2.3">>},
                         {<<"session_authorization">>,<<"postgres">>},
                         {<<"standard_conforming_strings">>,<<"on">>},
                         {<<"TimeZone">>,<<"US/Central">>}],
                        undefined,
                        {<0.1051.0>,#Ref<0.0.0.198>},
                        undefined,
                        {11102,347906346},
                        {statement,[],undefined,[int4]},
                        73}
** Reason for termination =
** {badarg,[{pgsql_binary,encode,2,[{file,"src/pgsql_binary.erl"},{line,14}]},
            {pgsql_connection,encode_parameter,1,
                              [{file,"src/pgsql_connection.erl"},{line,626}]},
            {pgsql_connection,encode_parameters,4,
                              [{file,"src/pgsql_connection.erl"},{line,618}]},
            {pgsql_connection,ready,3,
                              [{file,"src/pgsql_connection.erl"},{line,228}]},
            {gen_fsm,handle_msg,7,[{file,"gen_fsm.erl"},{line,494}]},
            {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]}
** exception exit: badarg
     in function  pgsql_binary:encode/2 (src/pgsql_binary.erl, line 14)
     in call from pgsql_connection:encode_parameter/1 (src/pgsql_connection.erl, line 626)
     in call from pgsql_connection:encode_parameters/4 (src/pgsql_connection.erl, line 618)
     in call from pgsql_connection:ready/3 (src/pgsql_connection.erl, line 228)
     in call from gen_fsm:handle_msg/7 (gen_fsm.erl, line 494)
     in call from proc_lib:init_p_do_apply/3 (proc_lib.erl, line 239)

Both queries work just fine if run manually from the command line, i.e.,

select name from servers where id in (1, 2, 3);

and

select name from servers where id = any (1, 2, 3);

both work fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions