g Verified current stable Not installed? Data Processing

G / Export Query Results To File

Export Query Results To File

Export the results of a SQL query to a specified file.

$
Terminal
\g <path/to/file_with_results>

When To Use

When generating reports or backing up query results.

Pro Tip

Use file format filtering (like CSV) to ensure compatible output files.

Anatomy of Output

Understanding the result

Successful export to path/to/file_with_results.csv Export Status

Indicates completion of the export process.

Rows affected: 5 Row Count

Number of rows exported to the file.

Execution Time: 0.020 sec Performance Metrics

Time taken for the export operation.

Troubleshooting

Common pitfalls

ERROR: could not open file "path/to/file_with_results": No such file or directory

Solution: Ensure the target directory exists and you have write permissions.

ERROR: export failed due to invalid query

Solution: Review the SQL query for accuracy before export.

ERROR: permission denied on exporting to file

Solution: Adjust file system permissions to allow write access.

Command Breakdown

What each part is doing

\g
Base Command
The executable that performs this operation. Here it runs G before the shell applies any redirect operators.
<path/to/file_with_results>
Input Files
The file path or paths supplied to this command.

Alternative Approaches

Comparable commands in other tools

Alternative data processing tools for the same job.