How can I get list of SQL commands for terminal on macOS?

How can i get a list of sql commands for terminal




[Re-Titled by Moderator]


iPhone 12, iOS 18

Posted on Apr 4, 2025 07:00 AM

Reply
2 replies

Apr 4, 2025 07:21 AM in response to Cxzsa22

There is no list of SQL commands for the Terminal shell. There are SQL syntax commands for the SQLite3 database included with macOS. Depending on the database implementation that you choose to use, its SQL language support may adhere to the formal ISO/IEC 9075:2023 SQL standard, or it may deviate with vendor-specific enhancements. In the latter case, see the vendor's related SQL documentation.


Here is a Zsh script that gets the Safari history data and outputs it to a CSV on the Desktop. One can then click on that CSV and press the space bar to use QuickLook to view it.


#!/bin/zsh

: <<'COMMENT'
Generate a CSV document with headers showing current Safari History
database content. You can view the columnar CSV in a scrollable QuickLook window,
or load it into a spreadsheet

Reference: http://2016.padjo.org/tutorials/sqlite-your-browser-history/

Usage in Terminal:
./sql_dtu.zsh > ~/Desktop/hist.csv

VikingOSX, 2020-07-16, Apple Support Communities, No warranties expressed or implied.
COMMENT

sqlite3 -header -csv $HOME/Library/Safari/History.db \
"SELECT DISTINCT
    datetime(visit_time + 978307200, 'unixepoch', 'localtime') AS visit_time,
    coalesce(nullif(title,''), 'Unavailable') as title, url
FROM
    history_visits
INNER JOIN
    history_items ON
        history_items.id = history_visits.history_item;"
exit 0


Apr 4, 2025 08:03 AM in response to Cxzsa22

You’ve posted this question in older Mac operating systems area, with an iPhone footer, with a title referencing terminal codes, asking about a database syntax. Tersely-worded questions can be surprisingly difficult to answer, too.


Could you describe what you’re trying to do, here?


Which macOS (or iOS) version is involved, too? (Your previous postings include an iMac running macOS 13.)


SQL (and particularly SQLite) is an option on iPhone, but there’s no command line available in iOS. SQL commands can be imbedded in iOS apps, however.


SQLite documentation is pretty good, and available at the SQLite website as linked in the reply above.


Depending on what goal you’re working toward here, another useful tool can be DB Browser for SQLite or alternative.


And part of the ambiguity: “terminal codes” can be a reference to escape and control codes, which are quite different from SQL. Or potentially to bash or zsh or other command syntax, which is a question headed in a yet-different direction.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How can I get list of SQL commands for terminal on macOS?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.