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

Post Gras

The document outlines the installation and basic usage commands for PostgreSQL, including database creation, table management, and user permissions. It provides step-by-step instructions for installing PostgreSQL, accessing the psql command line, and performing various SQL operations such as selecting, updating, and deleting data. Additionally, it covers transaction management and aggregate functions for data analysis.
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)
2 views3 pages

Post Gras

The document outlines the installation and basic usage commands for PostgreSQL, including database creation, table management, and user permissions. It provides step-by-step instructions for installing PostgreSQL, accessing the psql command line, and performing various SQL operations such as selecting, updating, and deleting data. Additionally, it covers transaction management and aggregate functions for data analysis.
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

POSTGRES

INSTALL COMMAND

step1:

sudo apt update

step2:

sudo apt install postgresql postgresql-contrib

step3:

psql –version

psql open:

sudo -i -u postgres

psql

view databass:

\l

TO Exit Psql

CREATE DATABASE:

create database std;

open database:

\c database name;

check table:

\dt

describle table:

\d table name:
view the table:

SELECT * FROM students;

SELECT name, grade FROM students;

SELECT * FROM students WHERE grade = 'A';

SELECT * FROM students ORDER BY age DESC;

SELECT COUNT(*) FROM students;

Table create;

create table name(id int,name varchar(20),salary int);

Insert values;

insert into table name values(‘09’,’ranjith’,’3000’);

Update & Delete

UPDATE students SET grade = 'A+' WHERE name = 'Ravi';

DELETE FROM students WHERE name = 'Amit';

Table Maintenance

TRUNCATE TABLE students; -- remove all rows

DROP TABLE students; -- delete table

6. 🔐 Users & Permissions


CREATE ROLE user1 WITH LOGIN PASSWORD 'pass123';

GRANT SELECT ON students TO user1;

REVOKE SELECT ON students FROM user1;

DROP ROLE user1;


Transactions

BEGIN;
UPDATE students SET grade = 'C' WHERE name = 'Priya';
ROLLBACK; -- Undo change

-- OR
COMMIT; -- Save change

Aggregate Functions

SELECT AVG(age) FROM students;

SELECT grade, COUNT(*) FROM students GROUP BY grade;

You might also like