SELECT product_type, COUNT(product_id)
FROM stock
GROUP BY product_type
COUNT()
: Returns the number of rows that fit the criteria stated in the WHERE clause.SUM()
: Calculates the total of all values in a column or an expression.AVG()
: Calculates the average column value.MIN()
: Returns the smallest value from a set.MAX()
: Returns the largest value from a set.WHERE
and HAVING
clauses.WHERE
and HAVING
clauses filter data and restrict unwanted data from appearing in your result set. The main difference between these filters is :WHERE
is applied at the record level.HAVING
is applied to sets of records.plugin_debugger
’ :shared_preload_libraries = ‘plugin_debugger’
Restart PostgreSQL
sudo service postgresql stop
sudo service postgresql start
CREATE EXTENSION pldbgapi;​
SELECT name
FROM employees
WHERE id IN
(SELECT id FROM sales_team)
INSERT
, UPDATE
, and DELETE
commands. Each of these operations has a different impact on the data inside your tables. Let’s take a look at the syntax of each of these statements.UPDATE table_name
SET column1 = value1,
column2 = value2,
…
[WHERE conditions]
SQL INSERT Syntax
You can write an INSERT
statement with or without explicitly declaring the column names. The syntax for using INSERT
without column names is:
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
Note that you’ll need to provide a value for every column in the table if you omit the column names.
If you want to add data to some or all the columns in a table, use INSERT
with column names:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
SQL DELETE Syntax
The syntax for using DELETE
is :
DELETE FROM table_name
[WHERE condition]
FROM
clause of a SELECT
, and you can reference view columns in SELECT
, WHERE
, GROUP BY
, and other clauses.CREATE VIEW european_customers AS
SELECT customer_id, customer_name
FROM customers
WHERE region = 'Europe';
SELECT *
FROM european_customers;
su -l pgsql
psql -l
Use CURRENT_TIMESTAMP:
CREATE TABLE tbl_name (a int, modtime TIMESTAMP DEFAULT
CURRENT_TIMESTAMP );
C:\Program Files\PostgreSQL\10.4\data
. Now, open the Command Prompt and execute the following commands :pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" start
pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" stop​
pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" restart
PostgreSQL | MongoDB |
---|---|
PostgreSQL is a classical, relational database server that supports most SQL standards. MongoDB is a NoSQL database. | |
PostgreSQL is a traditional relational database management system (RDBMS) or SQL-based databases like Oracle and MySQL. It is open-source and free to use. MongoDB is a no-schema, NoSQL, JSON format database. It also provides a free version, but its enterprise-paid versions are more popular. | |
PostgreSQL database is written in C language. | MongoDB is written in C++. |
PostgreSQL is a Relational Database Management System. | MongoDB is a Non-Relational Database Management System. |
PostgreSQL is an Object-Oriented Database. | MongoDB is Document Oriented Database. |
PostgreSQL is available in multiple languages. | MongoDB is only available in the English language. |
PostgreSQL is 4 to 10 times faster than MongoDB on some parameters. | MongoDB is slower than PostgreSQL. It is best suited for big data. |
Oracle | PostgreSQL |
---|---|
Oracle is mostly an aid object-relational database management system. It is the first database management system designed for grid computing. | PostgreSQL is a free, open-source object-relational database management system that follows SQL standards and extensibility. |
Oracle is written and implemented in C, C++, and assembly language. | PostgreSQL is written and implemented in C language. |
Oracle is a comparatively old database. It was developed by Larry Ellison and Bob on 16 June 1977. | PostgreSQL is comparatively a new database. It was developed by the PostgreSQL Global Development group on 8 July 1996. |
One must require a license to use Oracle. | PostgreSQL is open-source and free to use. |
In Oracle, server operating systems are OS X, Linux, Windows, z/OS, AIX, HP-UX, etc. | In PostgreSQL, server operating systems are HP-UX, NetBSD, Solaris, Windows, Unix, Linux, FreeBSD, etc. |
Oracle provides advanced security options. | PostgreSQL also provides good security support but less compared to Oracle. |
Oracle provides support for the programming languages such as C, C++, JAVA, PERL, .NET, JavaScript, PHP, etc. | PostgreSQL provides support for the programming languages such as C, C++, JAVA, PERL, SCALA, PHP, C#, COBOL, JavaScript, etc. |