Skip to content

Output single column from db query without formatting #145

@petenelson

Description

@petenelson

Feature Request

Describe your use case and the problem you are facing

The db query command currently formats the results in a table. While there is a --skip-column-names option (which doesn't show in the options when running help, only in the examples), there doesn't seem to be a way to disable the table formatting. While it may be possible to pass the results into a sed command to strip out the formatting, having it built-in without the extra steps may be handy.

Describe the solution you'd like

My use case was a query to get specific post IDs that I needed to pass to another command, ideally something like this:
wp db query --skip-column-names --format=csv "select ID from wp_4_posts where post_title like '%boston%' and post_type = 'hotel'"

This would give me just the post IDs in a list, which I could pipe to the paste command to turn them into a comma-delimited list, which I could pass to another command, ideally something like this, with a --column or --format flag.

wp elasticpress index --post-ids=$(wp db query --skip-column-names --column=ID "select ID from wp_4_posts where post_title like '%boston%' and post_type = 'hotel'" | paste -s -d, -)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions