

The process was smooth and pg_upgrade is a very handy tool.
Osx brew install postgresql upgrade#
I recently upgraded Postgres from 9.2 to 9.3 using brew upgrade postgres. Joins resulting datasets from multiple queries.I was looking for a long time, and this was the most clean and neat solution: JOIN programs USING (programid) GROUP BY program HAVING COUNT(*) > 1

Similar to WHERE but applies the condition to the groups produced with GROUP BY. JOIN programs USING (programid) GROUP BY program Ībove example counts students per program. SELECT * from students where programid IS NOT NULL Īllows use of aggregate functions with the attributes provided to the GROUP BY clause as basis for aggregations SELECT program, COUNT(*) FROM students Specify conditions by which rows from the query will be filtered. SELECT * FROM students RIGHT join programs on students.programid = programs.programid

We insert a program row without any students attached INSERT INTO programs(degree, program)ĭoing a right join would still return the recently inserted row but with empty Students-related fields. Right Join Syntax: SELECT * FROM table_1 RIGHT JOIN table_2 on table_1.column_name = table_2.column_name SELECT * FROM students LEFT join programs on students.programid = programs.programid We insert a student row without a program INSERT INTO students(student_number, first_name, last_name)ĭoing a left join would still return the recently inserted row but with empty Programs-related fields. Left Join Syntax: SELECT * FROM table_1 LEFT JOIN table_2 on table_1.column_name = table_2.column_name Inner Join Syntax: SELECT * FROM table_1 JOIN table_2 using (common_column_name) Įxample: SELECT student_number, program FROM students JOIN programs using (programid) Delete Rows Satisfying Conditions DELETE FROM students WHERE studentid NOT IN (1,2)
Osx brew install postgresql update#
UPDATE programs SET degree = 'BA' where programid NOT IN (2) ĭ. Update Rows Satisfying Conditions UPDATE students SET last_name = 'Santos' where studentid = 1 Update all Rows UPDATE students SET last_name = 'Cruz' SELECT 'BUSINESS PROGRAM: ' || program from programs where program ilike '%business%' Ĭ. # Selects the program column from rows of the programs table satisfying the condition and then prepending the given string SELECT last_name, firstname from students Get Specific Columns from Resulting Rows # Selects the lastname and firstname from the students table SELECT * FROM students where last_name ilike 'cru%' # Gets row/s where the last_name starts with 'cru' (non case sensitive) SELECT * FROM students where studentid = 1 Get Rows Satisfying Certain Conditions # Gets row/s with studentid = 1 INSERT INTO students(student_number, first_name, last_name, programid) VALUES('BS', 'Business Administration and Accountancy') Sample: INSERT INTO programs(degree, program) Template: INSERT INTO table_name(column1, column2, column3.) Insertedon TIMESTAMP WITHOUT TIME ZONE DEFAULT now() Once in, you may navigate via the following commands: To connect to a different port and/or host.

To connect to the PostgreSQL server with as user postgres: psql -U postgresīy default, psql connects to a PostgreSQL server running on localhost at port 5432. Sudo apt-get install postgresql postgresql-contrib
