2

I am trying to run basic postgresql commands which start with a backslash within Squirrel SQL sql client. For example, I'd like to be able to type

\dt 

to mean "SHOW TABLES" instead of

"SELECT * FROM information_schema.tables WHERE table_schema = 'public';"  

This works from the psql command line. However, when I try to run "\dt" within Squirrel I get a syntax error message:

Error: ERROR: syntax error at or near "\"
Position: 1
SQLState:  42601
ErrorCode: 0

I assume there's some kind of SQL syntax checking going on here on the part of Squirrel? Does any one know a way to make PostgreSQL commands which start with a backslash work in Squirrel SQL? I have the Postgres plugin installed...

Thanks,

vancan1ty
  • 563
  • 1
  • 4
  • 16
  • 1
    `\dt` is not a (regular) SQL command - it is specific to the command line client `psql` and thus cannot be run anywhere else than there. The SQL statements you can run are documented here: http://www.postgresql.org/docs/current/static/sql-commands.html –  Jan 26 '14 at 21:03
  • ah ok. But psql has some drawbacks as compared to a gui sql client -- for example, it doesn't display output with many columns well. Do you happen to know if there there is a gui sql client which does include the short backslash commands? – vancan1ty Jan 26 '14 at 21:05
  • I dont't think so, but then I have not used all clients that are out there: https://wiki.postgresql.org/wiki/Community_Guide_to_PostgreSQL_GUI_Tools But I'm surprised that Squirrel has no other way of listing the tables in a schema (I don't use Squirrel) –  Jan 26 '14 at 21:07
  • It does, but I dislike clicking through menus when I can type. Thanks. – vancan1ty Jan 26 '14 at 21:25

1 Answers1

5

The backslash commands are part of the psql client, not the PostgreSQL backend server. psql translates them into batches of SQL, which you can see by running psql with the -E flag, and uses the results to produce the displayed output.

This means you can't use these commands from other clients.

Alongside the inability to use pg_dump from within a PostgreSQL protocol session, or get equivalent functionality from the backend server, this is a bit of an FAQ.

At this point the only real option is to use a client that understands the information_schema or PostgreSQL's catalogs (pg_catalog) and can produce the display you want its self. A popular choice is PgAdmin-III, though I stick with psql myself.

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778