My problem is solved by the solution that wfgeo and ThingumaBob gave me.
I changed the query as:
select * from pgr_dijkstra('select id , source, target, cost FROM q_roads', 10237, 10551, false)
in fact the only difference with the previous one is adding false as the last argument. Previously, I did not write anything as last argument and it was true by ...
To use the result of a query within a function call, it must be enclosed in parentheses:
--geometry vs "select geometry" --> fail
select ST_Contains('point(0 0)',select 'point(0 0)');
ERROR: syntax error at or near "select"
LINE 1: select ST_Contains('point(0 0)',select 'point(0 0)');
--geometry vs "(select ...