SQLITE3(1)

๐Ÿ’– SQLITE3(1) โ€” a whole command line interface for SQLite version 3 ๐Ÿ’–

okay so bestie, this is SQLITE3(1), living its best life over in the General Commands Manual section, and it's literally the command-line era of SQLite version 3. Sit down, grab a boba, we're doing this. ๐Ÿง‹โœจ


โœจ SYNOPSIS โœจ

sqlite3 [options] [databasefile] [SQL]

that's it, that's the whole vibe check. ๐Ÿซถ


๐ŸŒˆ SUMMARY ๐ŸŒˆ

so sqlite3 is a terminal-based front-end to the SQLite library โ€” meaning it can evaluate queries interactively and show you the results in multiple formats. ๐Ÿ’…

and it's not just for vibing at a prompt either: sqlite3 can also be used inside shell scripts and other applications to provide batch processing features. main character energy in a cron job, honestly. ๐Ÿ‘‘


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

to start a sqlite3 interactive session, you just invoke the sqlite3 command and optionally hand it the name of a database file.

  • if the database file does not exist, it will be created โœจ
  • if the database file does exist, it will be opened ๐Ÿ’–

for example โ€” to create a new database file named mydata.db, create a table named memos, and insert a couple of records into that table:

$ sqlite3 mydata.db
SQLite version 3.43.0 2023-08-11 17:45:23
Enter ".help" for usage hints.
sqlite> create table memos(text, priority INTEGER);
sqlite> insert into memos values('deliver project description', 10);
sqlite> insert into memos values('lunch with Christine', 100);
sqlite> select * from memos;
deliver project description|10
lunch with Christine|100
sqlite>

look at her go. iconic. ๐ŸŽ€

if no database name is supplied, the ATTACH sql command can be used to attach to existing or create new database files. and ATTACH can also be used to attach to multiple databases within the same interactive session โ€” which is super useful for migrating data between databases, possibly changing the schema along the way. lowkey a glow-up pipeline. ๐Ÿ’ซ

optionally, a SQL statement or set of SQL statements can be supplied as a single argument. multiple statements should be separated by semicolons.

for example:

$ sqlite3 -line mydata.db 'select * from memos where priority > 20;'
    text = lunch with Christine
priority = 100

๐Ÿช„ SQLITE META-COMMANDS ๐Ÿช„

the interactive interpreter offers a set of meta-commands that can be used to:

  • control the output format ๐ŸŽจ
  • examine the currently attached database files ๐Ÿ”
  • perform administrative operations upon the attached databases (such as rebuilding indices) ๐Ÿ› ๏ธ

meta-commands are always prefixed with a dot (.). no cap.

a list of available meta-commands can be viewed at any time by issuing the .help command. for example:

sqlite> .help
the available commands differ by version and build options, so they are not listed here. please refer to your local copy for all available options. bestie, check your own house before you check mine. ๐Ÿ’€

๐ŸŒธ INIT FILE ๐ŸŒธ

sqlite3 reads an initialization file to set the configuration of the interactive environment. throughout initialization, any previously specified setting can be overridden. the sequence of initialization is as follows:

  1. the default configuration is established as follows:
mode            = LIST
separator       = "|"
main prompt     = "sqlite> "
continue prompt = "   ...> "
  1. if the environment variable XDG_CONFIG_HOME is set then ${XDG_CONFIG_HOME}/sqlite3/sqliterc is checked, else ~/.config/sqlite3/sqliterc is checked. if the selected file does not exist then the fallback of ~/.sqliterc is used. it should generally only contain meta-commands.
  2. if the -init option is present, the specified file is processed.
  3. all other command line options are processed.

that's the order, and it is not negotiable. periodt. ๐Ÿ’…


๐ŸŽ€ HISTORY FILE ๐ŸŽ€

sqlite3 may be configured to use a history file to save SQL statements and meta-commands entered interactively. these statements and commands can be retrieved, edited, and reused at the main and continue prompts. so cute, so practical. ๐Ÿซถ

  • if the environment variable SQLITE_HISTORY is set, it will be used as the name of the history file, whether it already exists or not.
  • if it is not set but the XDG_STATE_HOME environment variable is, then ${XDG_STATE_HOME}/sqlite_history is used.
  • if XDG_STATE_HOME is not set then ~/.local/state/sqlite_history is used.
  • if the selected file does not exist then ~/.sqlite_history will be used as the history file.

if any history file is found, it will be written if the shell exits interactive mode normally, regardless of whether it existed previously โ€” though saving will silently fail if the history file's directory does not exist. like it'll just ghost you, quietly. ๐Ÿ˜ญ no error, no note, nothing. bestie just make the directory, i'm begging. ๐Ÿ™ˆ


๐Ÿ”ฅ SEE ALSO ๐Ÿ”ฅ

go read, go click, go slay. ๐Ÿ‘‘


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

this manual page was originally written by Andreas Rottmann <rotty@debian.org>, for the Debian GNU/Linux system (but may be used by others). it was subsequently revised by Bill Bumgarner <bbum@mac.com>, Laszlo Boszormenyi <gcs@debian.hu>, and the sqlite3 developers. absolute legends, every single one. ๐Ÿซถโœจ


and that's the page!! dated Fri Aug 11 23:50:12 CET 2023, from your girl SQLITE3(1) in the General Commands Manual. stay hydrated, back up your databases, and remember: .help is always there for you. bye bestie, ily, go write some queries ๐Ÿ’–๐Ÿฆ‹๐ŸŒธ๐Ÿ’