Skip to content

Instantly share code, notes, and snippets.

@masamerc
Last active November 23, 2024 09:00
Show Gist options
  • Save masamerc/d503a8b6ea9e2e220da70cf6cd609734 to your computer and use it in GitHub Desktop.
Save masamerc/d503a8b6ea9e2e220da70cf6cd609734 to your computer and use it in GitHub Desktop.
duck-preview.sh
#!/usr/bin/env bash
# exit immediately
set -e
# check if filename is provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <filename>"
exit 1
fi
# check if file exists
if [ ! -f "$1" ]; then
echo "File not found: $1"
exit 1
fi
# setup
filename=$1
tmpdir=$(mktemp -d)
tmpdb=$tmpdir/duckdb.db
# cleanup for when script exits
function cleanup() {
if [ -d "$tmpdir" ]; then
rm -rf "$tmpdir"
fi
}
trap cleanup EXIT
# create a temporary duckdb database and start session
echo "creating database: $tmpdb"
echo "created table: preview from $1"
duckdb $tmpdb -c "CREATE TABLE preview AS SELECT * FROM '$filename';"
duckdb $tmpdb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment