PostgreSQL Documentation
Learn how to use PostgreSQL in your BackendGlitch project.
Installing PostgreSQL
To install PostgreSQL, follow these instructions for your operating system:
- Install Homebrew if you haven't already:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - Install PostgreSQL using Homebrew:
brew install postgresql - Start the PostgreSQL service:
brew services start postgresql
Connecting to PostgreSQL
To connect to your PostgreSQL database, use the following command:
psql -U postgresBasic PostgreSQL Commands
Here are some basic PostgreSQL commands to get you started:
-- Create a new database
CREATE DATABASE myapp;
-- Connect to the database
c myapp
-- Create a table
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100) UNIQUE NOT NULL
);
-- Insert data
INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com');
-- Query data
SELECT * FROM users;
-- Update data
UPDATE users SET name = 'Alicia' WHERE email = 'alice@example.com';
-- Delete data
DELETE FROM users WHERE email = 'alice@example.com';