Skip to content

Conversation

@DiegoDAF
Copy link

@DiegoDAF DiegoDAF commented Dec 5, 2025

Summary

This PR implements the -t/--tuples-only option, similar to psql's -t flag, which prints query results without status messages or timing information. This is useful for scripting and piping output to other commands.

Features

  • Default csv-noheader: pgcli -t outputs rows in CSV format without headers
  • Custom format: pgcli -t minimal allows specifying any table format
  • Suppresses extra output:
    • No "SELECT X" status messages
    • No "Time: X.XXXs" timing information
  • Clean for piping: Perfect for shell scripts and automation

Use Cases

# Get just the data, no headers or status
pgcli -t -c "SELECT oid FROM pg_roles WHERE rolname='postgres';"
# Output: 10

# Use with custom format
pgcli -t minimal -c "SELECT name, age FROM users LIMIT 3;"
# Output: aligned columns without headers

# Pipe to other commands
pgcli -t -c "SELECT email FROM users;" | while read email; do
  echo "Sending to $email"
done

Implementation Details

  • Added tuples_only field to OutputSettings namedtuple
  • Added tuples_only parameter to PGCli.__init__()
  • Modified format_output() to skip status when tuples_only=True
  • Modified timing output logic to respect tuples_only flag
  • Click option configured as is_flag=False with flag_value="csv-noheader"
    • Using -t alone defaults to csv-noheader
    • Using -t <format> allows custom formats

Compatibility

  • Does not affect existing functionality when flag is not used
  • Works independently of other flags
  • Compatible with all existing table formats
  • Follows psql behavior

Made with ❤️ and 🤖 Claude Code

…utput

This commit implements a new --tuples-only option similar to psql's -t flag,
which prints query results without status messages or timing information.

Features:
- `-t` or `--tuples-only` without value defaults to csv-noheader format
- `-t <format>` allows specifying any table format (e.g., `-t minimal`)
- Suppresses "SELECT X" status messages when enabled
- Suppresses "Time: X.XXXs" timing output when enabled
- Does not affect normal output when option is not used

Implementation details:
- Added `tuples_only` parameter to PGCli.__init__()
- Added `tuples_only` field to OutputSettings namedtuple
- Modified format_output() to skip status when tuples_only is True
- Modified timing output logic to skip when tuples_only is True
- Preserves all existing functionality when flag is not used

Example usage:
  pgcli -t -c "SELECT oid FROM pg_roles WHERE rolname='user';"
  # Output: 2124219 (nothing else)

  pgcli -t minimal -c "SELECT oid, rolname FROM pg_roles LIMIT 3;"
  # Output: aligned columns without headers or status

Made with ❤️ and 🤖 Claude Code
@DiegoDAF DiegoDAF marked this pull request as ready for review December 5, 2025 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant