PostgreSQL Queries syntax:
Data types:
character varying(n), varchar(n) --> variable-length with limit
character(n), char(n) --> fixed-length
text --> variable unlimited length
integer or int --> this type is for integer, and also we have few variants for bigger and smaller integers(ie smallint,bigint)
timestamp --> time and date
time --> only time(ie HH:MM:SS)
date --> only date
PostgreSQL queries syntaxs are mostly like oracle
insert Query:
Syntax1: to insert values into paticular columns
INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)
VALUES (value1, value2, value3,...valueN);
Syntax2:to insert into all columns
INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN);
select Query:
SELECT column1, column2, columnN FROM table_name;
update Query:
UPDATE table_name
SET column1 = value1, column2 = value2...., columnN = valueN
WHERE [condition];
delete Query:
DELETE FROM table_name
WHERE [condition];
alter Query:
Few Examples:
ALTER TABLE EMP ADD COLUMN address varchar(30);
ALTER TABLE EMP DROP COLUMN address;
ALTER TABLE distributors
ALTER COLUMN address TYPE varchar(80),
ALTER COLUMN name TYPE varchar(100);
drop Query:
DROP TABLE table_name;
like and ilike:
SELECT FROM table_name
WHERE column LIKE 'XXXX';
ILIKE is to ignorecase
SELECT FROM table_name
WHERE column ILIKE 'XXXX';
Wildcards % and _ can be used in search string.
limit clause:
SELECT column1, column2, columnN
FROM table_name
LIMIT [no of rows] OFFSET [row num]
order by clause:
SELECT column-list
FROM table_name
[WHERE condition]
[ORDER BY column1, column2, .. columnN] [ASC | DESC];
group by clause:
SELECT column-list
FROM table_name
WHERE [ conditions ]
GROUP BY column1, column2....columnN
ORDER BY column1, column2....columnN
having clause:
SELECT column-list
FROM table_name
WHERE [ conditions ]
GROUP BY column1, column2....columnN
ORDER BY column1, column2....columnN
also see below
what is postgreSQL
Why postgresSQL
History of PostgreSQL
postgreSQL - PSQL MATA Commands
postgreSQL what is schema?
postgreSQL Connecting to a Database
postgreSQL Create and access Database
How to create user in postgreSQL?
postgreSQL Grant/Revoke Privileges
postgreSQL Tablespaces and datafiles
postgreSQL How to start server and stop server?
postgreSQL perfomance
postgreSQL How to create cluster?
postgreSQL Queries
postgreSQL routine maintenance and proactive-maintanace.
postgresql-logging