Skip to main content Link Menu Expand (external link) Document Search Copy Copied

fbsql output flags

fbsql output can be configured from the command-line or fbsql interface to:

  • direct CLI and interface history to a new directory
  • change the working directory
  • create a file to output SQL query results and comments

Before you begin

Enter fbsql --help at the CLI to list available commands. \q quits the fbsql interface.

Syntax

(<meta-prefix>)
  [--history-path="<directory-name>"] |
  [cd [<directory-name>]] |
  [[o | out] <query-output-filename>] |
  [qecho <text>] |
  [warn <text>]
]

Meta-command flag prefix

Meta-command flags can be run from the fbsql interface or CLI using an appropriate prefix:

Interface Prefix Description Example
fbsql \ Leading backslash followed by one or more meta-command flags and arguments separated by \ backslash characters. \print \echo "this is a test"
CLI fbsql [-c|--command] Meta-command flags enclosed in single or double quotes are executed without opening the fbsql interface fbsql --command '\print \echo this is a test'

History logs

Flag Description Default
--history-path="<directory-name>" Save CLI and fbsql interface execution history to new folder <user-home>.featurebase/fbsql_history

File output

Flag Description Additional information
cd [<directory-name>] Set fbsql file directory to $home or specified directory Default is Directory fbsql started

Write text to output

Flag Description
[o | out] <query-output-filename> Define existing file to output query results
echo <text> Output <text> to fbsql interface
qecho <text> Output <text> to file defined by \[o|output <output-filename>]
warn <text> Output <text> to fbsql standard error channel

Additional information

Flag execution

  • Flags can be executed individually or as a sequence delimited by \
  • Use single quotation marks ' ' to insert whitespace

fbsql query buffer

The query buffer holds partial or not executed:

  • meta-commands
  • SQL queries

Examples

Create directory and open

\! mkdir newfolder
\cd newfolder

Output query results to file

\out output-test.sql
\! ls
output-test.sql

Write comment to file

\qecho Testing 1,2,3
\! cat output-test.sql
Testing 1,2,3

Run query and verify output saved to correct file

select * from products;
\! cat output-test.sql

Testing 1,2,3
 _id | item                 | price  | stock
-----+----------------------+--------+-------
   1 | pen                  | 2.50   | NULL
   2 | pencil               | 0.50   | NULL
   3 | playpen              | 52.50  | NULL
   4 | gold-plated earplugs | 122.50 | NULL
(0 rows)

Further information