psql -d appdb -c "CREATE TABLE IF NOT EXISTS users (id serial PRIMARY KEY, email text UNIQUE);"

Category: Databases & SQL

psql -d appdb -c "CREATE TABLE IF NOT EXISTS users (id serial PRIMARY KEY, email text UNIQUE);"

Create a table only if missing

serial makes an auto-incrementing integer column, PRIMARY KEY adds a unique index, and UNIQUE forbids duplicate emails. IF NOT EXISTS silently skips when the table is already there. Useful in idempotent setup scripts.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.