Hadoop Online Tutorials

Postgres Commands

CREATE

We can see our new table by typing this:

List of relations

Schema |    Name    | Type  |  Owner

——–+————+——-+———-

public | playground | table | postgres

(1 row)

INSERT

 

Ex: INSERT oid 1

Ex: INSERT 0 #

SYNTAX:

INSERT INTO TABLE_NAME (Column1,column2,…columnN) VALUES (value1,value2,….valueN);

SELECT

output will be look like

equip_id | type  | color  | location  | install_date

———-+——-+——–+———–+————–

1 | slide | blue   | south     | 2014-04-28

2 | swing | yellow | northwest | 2010-08-16

(2 rows)

DELETE

ALTER

UPDATE

LIKE CLAUSE

LIMIT CLAUSE

From the above command psql will fetch the total as 4 rows and starting with 2nd row.

LIMIT=no of rows to be returned.

OFFSET= starting of the row number.

ORDER BY

GROUP BY

WITH CLAUSE

WITH provides a way to write subqueries for use in a larger SELECT query. The subqueries, which are often referred to as Common Table Expressions or CTEs, can be thought of as defining temporary tables that exist just for this query. One use of this feature is to break down complicated queries into simpler parts. An example is:

Basic Syntax:

HAVING CLAUSE

HAVING CLAUSE is like a where condition associated with GROUP BY

Basic Syntax:

DISTINCT