pgcli
pgcli copied to clipboard
Add support for -t/--tuples-only option to print rows without extra output
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 -toutputs rows in CSV format without headers - Custom format:
pgcli -t minimalallows 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_onlyfield toOutputSettingsnamedtuple - Added
tuples_onlyparameter toPGCli.__init__() - Modified
format_output()to skip status whentuples_only=True - Modified timing output logic to respect
tuples_onlyflag - Click option configured as
is_flag=Falsewithflag_value="csv-noheader"- Using
-talone defaults to csv-noheader - Using
-t <format>allows custom formats
- Using
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