Dear readers of our blog, we'd like to recommend you to visit the main page of our website, where you can learn about our product SQLS*Plus and its advantages.
 
SQLS*Plus - best SQL Server command line reporting and automation tool! SQLS*Plus is several orders of magnitude better than SQL Server sqlcmd and osql command line tools.
 

REQUEST COMPLIMENTARY SQLS*PLUS LICENCE

Enteros UpBeat offers a patented database performance management SaaS platform. It proactively identifies root causes of complex revenue-impacting database performance issues across a growing number of RDBMS, NoSQL, and deep/machine learning database platforms. We support Oracle, SQL Server, IBM DB2, MongoDB, Casandra, MySQL, Amazon Aurora, and other database systems.

PostgreSQL tutorial

15 September 2020

PostgreSQL tutorial

PostgreSQL is a powerful Open Source Object-Relational Database System. It has over 15 years of the active development phase and a proven architecture that has earned a good reputation for reliability, data integrity, and accuracy.

This tutorial will give you a quick start with PostgreSQL and allows you to get used to PostgreSQL programming.
PostgreSQL data types
Literals
Announcement of variables
Comments
Aliases (pseudonyms)

PostgreSQL functions

PostgreSQL function date/time

Function & Description
AGE
The age PostgreSQL function returns the number of years, months, and days between two dates.
CURRENT_DATE
The current_date function in PostgreSQL returns the current date.
CURRENT_TIME
The current_time function in PostgreSQL returns the current time with time zone.
CURRENT_TIMESTAMP
The current_timestamp PostgreSQL function returns the current date and time with the time zone.
DATE_PART
The date_part PostgreSQL function extracts parts from the date.
EXTRACT
The extract PostgreSQL function extracts parts from the date.
LOCALTIME
The local time PostgreSQL function returns the current time.
LOCALTIMESTAMP
The localtimestamp PostgreSQL function returns the current date and time.
NOW
The now PostgreSQL function returns the current time and date with the time zone.

 

PostgreSQL string functions

Function & Description
BTRIM
The PostgreSQL btrim function removes all specified characters both at the beginning and at the end of a line.
CHAR_LENGTH
The char_length function in PostgreSQL returns the length of the specified string.
CHARACTER_LENGTH
The character_length function in PostgreSQL returns the length of the specified string.
INITCAP
The function initcap PostgreSQL converts the first letter of each word to upper case, and all other letters are converted to lower case.
LENGTH
The length PostgreSQL function returns the length of the specified string, expressed in the number of characters.
LOWER
The lower PostgreSQL function converts all characters of a specified string into lower case.
LPAD
The PostgreSQL lpad function returns a string added to the left side of the specified string of a certain length.
LTRIM
The ltrim PostgreSQL function removes all specified characters on the left side of the line.
POSTGRESQL operator ||
PostgreSQL operator || allows to combine 2 or more lines together.
POSITION
The PostgreSQL position function returns the substring location in a string.
REPEAT
The repeat PostgreSQL function repeats the string as many times as specified.
REPLACE
The replace PostgreSQL function replaces all occurrences of the specified string.
RPAD
The PostgreSQL rpad function returns a string added to the right side of the specified string of a certain length.
RTRIM
The PostgreSQL rtrim function removes all specified characters on the right side of the line.
STRPOS
The PostgreSQL strpos function returns the substring arrangement in a string.
SUBSTRING
The substring PostgreSQL function allows extracting substring from a string.
TRANSLATE
The translate PostgreSQL function replaces a sequence of characters in a string with another set of characters. However, it replaces one character at a time.
For example, it replaces the first character in string_to_replace with the first character in replace_string. Then it will replace the second character in string_to_replace with the second character in replace_string, etc.
TRIM
The trim PostgreSQL function removes all specified characters from the beginning or end of a line.
UPPER
PostgreSQL function upper converts all characters in a specified string into upper case.

 

PostgreSQL conversion functions

Function & Description
TO_CHAR
The PostgreSQL to_char function converts a number or date to a string.
TO_DATE
The to_date function in PostgreSQL converts a string into a date.
TO_NUMBER
The PostgreSQL to_number function converts a string into a number.
TO_TIMESTAMP
The PostgreSQL to_timestamp function converts a string into a timestamp.

 

Numerical/mathematical PostgreSQL functions

Function & Description
ABS
The abs function in PostgreSQL returns the absolute value of the number.
AVG
The avg PostgreSQL function returns the average value of the expression.
CEIL
The ceil PostgreSQL function returns the smallest integer value, which is greater than or equal to a number.
CEILING
The ceiling PostgreSQL function returns the smallest integer value, which is greater than or equal to a number.
COUNT
The count PostgreSQL function returns the number of expressions.
DIV
The div PostgreSQL function is used for integer division, where n is divided by m and integer value is returned.
EXP
The exp function in PostgreSQL returns e, raised to number (or enumber).
FLOOR
The floor PostgreSQL function returns the largest integer value that is less than or equal to a number.
MAX
The function max PostgreSQL returns the maximum value of the expression.
MIN
The min function in PostgreSQL returns the minimum value of the expression.
MOD
The mod PostgreSQL function returns the residue from n divided by m.
POWER
The power PostgreSQL function returns the value of m, which is elevated to n-th degree.
RANDOM
The random PostgreSQL function can be used to return a random number or a random number within a range.
ROUND
The round PostgreSQL function returns a number rounded to a certain number of decimal places.
SETSEED
The setseed PostgreSQL function can be used to set the initial number the next time the random function is called. If you do not call setseed, PostgreSQL will use its own seed value. This may or may not be really random.
If you set the initial value by calling setseed, then random will return a repeatable sequence of random numbers obtained from the initial number.
Tip: The setseed function can be very useful in situations where you want to make sure that PostgreSQL uses a really random starting number.
SIGN
The sign PostgreSQL function returns a value that denotes a number sign.
SQRT
The function sqrt PostgreSQL returns the square root of the number.
SUM
The sum PostgreSQL function returns the cumulative value of the expression.
TRUNC
The trunc PostgreSQL function returns a number truncated to a certain number of decimal places.

 

PostgreSQL query types

SELECTGet records from the table
SELECT LIMITGet records from the table and limit the number of records
DISTINCTUsed to remove duplicates from the result set
FROMUsed for displaying tables and any associations
WHEREUsed to filter the results
ORDER BYUsed to sort the results
GROUP BYUsed to group the results
HAVINGUsed in combination with the GROUP BY operator to limit groups of returned strings only to those whose TRUE condition
INSERTOperator for inserting a row into a table
UPDATEThe operator of data update in the table
DELETEOperator to delete data from the table
UNIONOperator to combine sets of results with the removal of repeating rows
UNION ALLOperator to combine sets of results without removing repeating lines
INTERSECTThe operator returns the general records of the result sets
EXCEPTSet of results from one minus set of results from another
SubqueriesAttached request (subquery)
JOIN TablesUsed to extract data from multiple tables

 

PostgreSQL database administration

Create UserCreate a database account
Grant/Revoke PrivilegesGranting and cancellation of privileges in the database
Change PasswordChange user password
Find UsersUser search
Find Users Logged InFind users who are logged in to PostgreSQL
Rename UserRename user
Drop UserDelete user
VacuumCleaning up unused space in the database
Auto_VacuumThe process that automatically cleans unused space in the database

 

PostgreSQL tables and views

CREATE TABLECreate a table
CREATE TABLE ASCreate a table from the data of another table
ALTER TABLEAdd, edit, delete columns in the table; rename the table
DROP TABLEDelete the table
TRUNCATE TABLEDelete all records from the table (with the optimizer)
VIEWVirtual table (representation of other tables)

 

PostgreSQL keys, indexes, and restrictions

Primary KeysCreate, add and delete primary keys
IndexesCreate, delete and rename indices (performance tuning)
Unique ConstraintsCreate, add and remove unique constraints

 

PostgreSQL conditions

ANDLogical operator AND
ORLogical operator OR
AND and ORLogical operator AND and OR
LIKEDetermines whether the specified character string coincides with the specified template
INDetermines whether a specified value matches a value in a nested query or list
NOTNegation of conditions
IS NULLUsed to check the NULL value
IS NOT NULLUsed to check the NOT NULL value
BETWEENDefines the range to check the condition
EXISTSIn the WHERE proposal of an external query, the presence of strings returned by an attached query is checked.

 

PostgreSQL comparison statements

Comparison OperatorsComparison operators such as =, <>, !=, >, < and others

 

Learn PostgreSQL Tutorial – Full Course for Beginners

 
Tags: , ,

MORE NEWS

 

Preamble​​NoSql is not a replacement for SQL databases but is a valid alternative for many situations where standard SQL is not the best approach for...

Preamble​​MongoDB Conditional operators specify a condition to which the value of the document field shall correspond.Comparison Query Operators $eq...

5 Database management trends impacting database administrationIn the realm of database management systems, moreover half (52%) of your competitors feel...

The data type is defined as the type of data that any column or variable can store in MS SQL Server. What is the data type? When you create any table or...

Preamble​​MS SQL Server is a client-server architecture. MS SQL Server process starts with the client application sending a query.SQL Server accepts,...

First the basics: what is the master/slave?One database server (“master”) responds and can do anything. A lot of other database servers store copies of all...

Preamble​​Atom Hopper (based on Apache Abdera) for those who may not know is an open-source project sponsored by Rackspace. Today we will figure out how to...

Preamble​​MongoDB recently introduced its new aggregation structure. This structure provides a simpler solution for calculating aggregated values rather...

FlexibilityOne of the most advertised features of MongoDB is its flexibility.  Flexibility, however, is a double-edged sword. More flexibility means more...

Preamble​​SQLShell is a cross-platform command-line tool for SQL, similar to psql for PostgreSQL or MySQL command-line tool for MySQL.Why use it?If you...

Preamble​​Writing an application on top of the framework on top of the driver on top of the database is a bit like a game on the phone: you say “insert...

Preamble​​Oracle Coherence is a distributed cache that is functionally comparable with Memcached. In addition to the basic function of the API cache, it...

Preamble​​IBM pureXML, a proprietary XML database built on a relational mechanism (designed for puns) that offers both relational ( SQL / XML ) and...

  What is PostgreSQL array? In PostgreSQL we can define a column as an array of valid data types. The data type can be built-in, custom or enumerated....

Preamble​​If you are a Linux sysadmin or developer, there comes a time when you need to manage an Oracle database that can work in your environment.In this...

Preamble​​Starting with Microsoft SQL Server 2008, by default, the group of local administrators is no longer added to SQL Server administrators during the...