I am using Rails 4. I am trying to list all PostgreSQL databases with '\l' using 'execute' method from ActiveRecord. Connection is correctly established.
p = ActiveRecord::Tasks::PostgreSQLDatabaseTasks.new(configuration)
p.send 'establish_master_connection'
p.connection.execute('\l')
Here is the error:
ActiveRecord::StatementInvalid (PG::SyntaxError: ERROR: syntax error at or near "l"
When I use 'no slash' method it works fine
connection.execute("DROP DATABASE IF EXISTS NOTHING")
=> #<PG::Result:0xc5e6094 status=PGRES_COMMAND_OK ntuples=0 nfields=0 cmd_tuples=0>
Any idea?
\l
is not a SQL statement, it's a command specific topsql
. The only "interface" through which you can run that ispsql