xo / usql

Universal command-line interface for SQL databases
MIT License
8.81k stars 346 forks source link

possibility to redirect \d psql meta-command execution into a file #426

Closed LuisBL closed 3 months ago

LuisBL commented 8 months ago

Does that make sens or is there a more natural way to do this ?

usql your_database

-- Within usql
your_database=> \dt > output.txt
LuisBL commented 8 months ago

The closer I get is:

sq:northwind.db=> \p
Query buffer is empty.
sq:northwind.db=> \! cat input.sql
\echo ====== test to pipe in out from usql
\d Regions
sq:northwind.db=> \i input.sql
====== test to pipe in out from usql
                 TABLE "Regions"
       Name        |  Type   | Nullable | Default 
-------------------+---------+----------+---------
 RegionDescription | TEXT    | "NO"     |  
 RegionID          | INTEGER | "NO"     |  

sq:northwind.db=> \o output.txt
sq:northwind.db=> \! wc -l output.txt
0 output.txt
sq:northwind.db=> \i input.sql
====== test to pipe in out from usql
                 TABLE "Regions"
       Name        |  Type   | Nullable | Default 
-------------------+---------+----------+---------
 RegionDescription | TEXT    | "NO"     |  
 RegionID          | INTEGER | "NO"     |  

sq:northwind.db=> \! wc -l output.txt
0 output.txt
sq:northwind.db=>  

no way to send the result of the execution of input.sql to output.txt

nineinchnick commented 8 months ago

Can you describe your use case more, why you want to save this output to a file?

LuisBL commented 8 months ago

It's to keep a trace of the full session in a text file

nineinchnick commented 8 months ago

Why do you want that? It's not a regular session, as you don't see the output.