Posted by Kyle Hankinson September 23, 2020

SQLPro supports multiple cursors. This allows a users to perform certain actions with fewer keystrokes.

There are two different ways available to select multiple cursors. The first, is by holding Option while dragging the mouse cursor up or down between lines.

The second method is by using the keyboard shortcut Command + Option along with ↑/↓.

Once multiple cursors have been selected, the following keyboard shortcuts are available.

  • ←/→ to move text selection to the left and right one character.
  • Option + ←/→ to move text selection left/right one word.
  • Shift + ←/→ to move and highlight text selection to the left and right.
  • Shift + Option + ←/→ to move and highlight text selection left/right one word.
  • Cmd + Delete to delete from the curors beginnings to the end of the next word.
  • Option + Delete to delete from the curors beginnings to the end of the line.

Any feedback or issues with multi-cursor support should be added to the origional request ticket.

Tags: Feature

Counting tables rows in a PostgreSQL database

Posted by Kyle Hankinson August 14, 2020


Need to find out how many rows, or how much data your PostgreSQL tables are consuming? Possibly, looking to find out what the largest tables in the database are? There are a couple of options available depending on your needs.

Single Table

Finding out how many rows are in a single table is the easiest task. Simply run the query:


You will get a single row result which contains the number of rows:from the specified table.

| count(1) |
| 7        |

Multiple Tables

Counting rows from multiple tables at once is a bit more difficult. You can get an estimate by using the following query:

    schemaname as table_schema, relname as table_name, n_live_tup as row_count
    n_live_tup DESC;

A more accurate way to get exact row counts courtesy of stackoverflow would be:

select table_schema, 
       (xpath('/row/cnt/text()', xml_count))[1]::text::int as row_count
from (
  select table_name, table_schema, 
         query_to_xml(format('select count(*) as cnt from %I.%I', table_schema, table_name), false, true, '') as xml_count
  from information_schema.tables
  where table_schema = 'public' --<< change here for the schema you want
) t order by 3 DESC

Using this second method will take longer and be more likely to slow-down other database operations, however the count will be more accurate.

Size on disk

Sometimes row count might not be exactly what you are looking for. If you need to find out how large a table is in bytes, the pg_relation_size method will come to your help. Finding the size for all tables would be:

    pg_size_pretty(pg_relation_size(schemaname || '.' || tablename))

Which will give the schema, table and pretty printed size for each table.

Tags: PostgreSQL

Killing/cancelling a long running Postgres query

Posted by Kyle Hankinson August 12, 2020

Finding the PID

The first thing you will need to do in order to kill or cancel a PostgreSQL query is to find the PID. This can be found by running the following query:

SELECT * FROM pg_stat_activity WHERE state = 'active';

Now that you have the PID, there are two options for killing the query.

Option #1 (graceful):

SELECT pg_cancel_backend(<PID>);

Option #2 (forceful):

SELECT pg_terminate_backend(<PID>);

Generally, Option #1 should be used as it gracefully terminates the query. Sometimes, however the query still continues to run for a long period of time even after being gracefull terminated. This is when Option #1 should be used.

Terminate all queries

If you want to terminate all running queries, the following statement can be executed:

SELECT pg_cancel_backend(pid) FROM pg_stat_activity WHERE state = 'active' and pid <> pg_backend_pid();

The above statement will kill all active queries and should only be used in special situations.

Tags: PostgreSQL

Server based results sorting

Posted by Kyle Hankinson August 12, 2020


Server based results sorting is a helpful and quick way for users to sort all results from a table without needing to write SQL. As of SQLPro v2020.71 is has been enabled by default. Using it is easy as can be. Simply click the header of a result set. The updated sort statement appear 'ghosted' in your query.

How to disable

Server based sorting can be disabled via the 'SQLPro' -> 'Preferences' menu item. Once the preferences dialog is visible uncheck the 'Server based results sorting'.


Server based sorting only works for simple queries. If the query is complex, then the results will be sorted locally using the 'in memory results'.

Tags: Feature

Autocomplete delay

Posted by Kyle Hankinson June 30th, 2020

The autocomplete delay option is a perference which allows users to determine the time it takes for the autocomplete window to be displayed when typing in the query editor. It can be found on the General page of SQLPro Preferences.

The default autocomplete delay is 1.25 seconds. With the delay, autocomplete would appear as follows.

autocomplete default

Setting the autocomplete delay to 0 would display autocomplete after most-every keystroke.

autocomplete default


When entering a database, schema or table, followed by a period, such as:

SELECT * FROM myDatabase.

Autocomplete will instantly appear showing all children of the parent object.

Autocomplete will also not appear automatically after the following characters: ;\"),

It has generally been found that users tend to want whitespace (such as a newline, space, tab, etc) after those characters. Autocomplete can still be triggered by hitting escape.

Tags: Feature

More articles: