[go: up one dir, main page]

0% found this document useful (0 votes)
3 views3 pages

PostgreSQL Psql Commands Guide

The document provides an overview of PostgreSQL (psql) commands, operators, and functions, including basic meta-commands, SQL basics, PostgreSQL-specific features, data types, common operators, and useful functions. It also includes recommended YouTube resources for learning PostgreSQL. Key features highlighted include JSON storage, auto-incrementing integers, and common table expressions.

Uploaded by

pebagat746
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

PostgreSQL Psql Commands Guide

The document provides an overview of PostgreSQL (psql) commands, operators, and functions, including basic meta-commands, SQL basics, PostgreSQL-specific features, data types, common operators, and useful functions. It also includes recommended YouTube resources for learning PostgreSQL. Key features highlighted include JSON storage, auto-incrementing integers, and common table expressions.

Uploaded by

pebagat746
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

PostgreSQL (psql) Commands, Operators, and Functions

Basic psql Meta-Commands

\l - List all databases

\c dbname - Connect to a database

\dt - List all tables in the current schema

\d tablename - Describe a table

\du - List all roles

\q - Quit the psql shell

SQL Basics (Common to SQL, MySQL, PostgreSQL)

SELECT * FROM table; - Retrieve all records

INSERT INTO table (col1, col2) VALUES (...);

UPDATE table SET col1 = val WHERE ...;

DELETE FROM table WHERE ...;

CREATE TABLE table (...);

DROP TABLE table;

PostgreSQL-Specific Features

SERIAL - Auto-incrementing integer

JSON / JSONB - JSON data storage

ARRAY - Store arrays in a column

RETURNING clause - Return values after insert/update/delete

UPSERT using ON CONFLICT - INSERT ... ON CONFLICT DO UPDATE ...

CTEs (WITH clause) - Common Table Expressions

Data Types in PostgreSQL


PostgreSQL (psql) Commands, Operators, and Functions

INTEGER, SERIAL, BIGINT

VARCHAR(n), TEXT

BOOLEAN

DATE, TIME, TIMESTAMP

JSON, JSONB

ARRAY

Common Operators

= <> != < > <= >= - Comparison

AND OR NOT - Logical

LIKE, ILIKE - Pattern matching (ILIKE = case-insensitive)

IS NULL, IS NOT NULL - Null checks

IN (val1, val2, ...) - Match multiple values

Useful PostgreSQL Functions

String: LOWER(), UPPER(), LENGTH(), SUBSTRING()

Math: ROUND(), CEIL(), FLOOR(), POWER(), RANDOM()

Date/Time: NOW(), CURRENT_DATE, AGE(), EXTRACT()

JSON: ->, ->>, #>, #>> (for JSON/JSONB)

Aggregate: COUNT(), SUM(), AVG(), MAX(), MIN()

Recommended YouTube Resources

1. Programming with Mosh - PostgreSQL Tutorial for Beginners

https://www.youtube.com/watch?v=qw--VYLpxG4

2. Amigoscode - PostgreSQL Crash Course


PostgreSQL (psql) Commands, Operators, and Functions

https://www.youtube.com/watch?v=Qp6xJb-uxzo

3. The Net Ninja - PostgreSQL Tutorial Series

https://www.youtube.com/playlist?list=PL4cUxeGkcC9jLYyp2Aoh6hcWuxFDX6PBJ

You might also like