Skip to content

Feature request: show transaction status in pgcli prompt (%x, like psql) #1552

@devadathanmb

Description

@devadathanmb

pgcli currently shows transaction status in the bottom bar but doesn't support displaying it in the prompt. psql supports this via the %x escape sequence in prompt configuration.

psql behavior:

In psql, you can include transaction status directly in your prompt like:

\set PROMPT1 '%n@%/%x%# '

The %x escape shows:

  • Empty string when not in a transaction
  • * when in a transaction block
  • ! when in a failed transaction block
  • ? when transaction state is indeterminate

Example prompts:

user@mydb  # SELECT 1;          -- no transaction
user@mydb* # SELECT 1;          -- in transaction
user@mydb! # SELECT 1;          -- failed transaction

While the bottom status bar does show this info, having it in the prompt is useful when reviewing scrollback or terminal recordings, and it's what many users are accustomed to from psql. Transactions are core to database work, so prompt-level visibility helps catch mistakes like forgetting you're in a transaction block.

For reference, this behavior is documented in the psql prompt escape sequences: %x transaction status indicator — https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-PROMPTING

If this is something the maintainers are open to, I'm happy to contribute a PR. Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions