PostgreSQL Documentation

Learn how to use PostgreSQL in your BackendGlitch project.

Installing PostgreSQL

To install PostgreSQL, follow these instructions for your operating system:

  1. Install Homebrew if you haven't already:
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. Install PostgreSQL using Homebrew:
    brew install postgresql
  3. Start the PostgreSQL service:
    brew services start postgresql

Connecting to PostgreSQL

To connect to your PostgreSQL database, use the following command:

psql -U postgres

Basic 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';