The new features on the SQL statement, are explained here.
3.4.1 Enhancement of the COPY statement
In the prior version it was able to use the COPY statement to output the results of the SELECT statement to a file or standard output. In PostgreSQL 9.6, by specifying the UPDATE / DELETE / INSERT statements to the COPY statement, it will be able to output the affected records.
Example 19Specify the DELETE statement to COPY statement
postgres=# COPY (DELETE FROM data1 WHERE col1 < 100 RETURNING *) TO
'/home/postgres/data1.csv' ;
COPY 5
postgres=# COPY (DELETE FROM data1 WHERE col1 < 100) TO
'/home/postgres/data1.csv' ;
ERROR: COPY query must have a RETURNING clause
3.4.2 Enhancement of the ALTER TABLE ADD COLUMN statement
The ALTER TABLE ADD COLUMN statement to add a column, IF NOT EXISTS clause to check for the existence of the column can now be specified. Only if the specified column does not exist, add column operation will be performed. Syntax
Example 21ALTER TABLE ADD COLUMN IF NOT EXISTS statement
postgres=> ALTER TABLE data1 ADD COLUMN c3 CHAR(1) ;
ALTER TABLE
postgres=> ALTER TABLE data1 ADD COLUMN IF NOT EXISTS c3 CHAR(1) ;
NOTICE: column "c3" of relation "data1" already exists, skipping
ALTER TABLE
postgres=> ALTER TABLE data1 ADD COLUMN IF NOT EXISTS c4 CHAR(1) ;
ALTER TABLE
3.4.3 Enhancement of the ALTER TABLESPACE SET statement
In PostgreSQL 9.6 it is now possible to set the parameter effective_io_concurrency for each tablespace. Parameters that can be specified for each tablespace in the old version was only random_page_cost and seq_page_cost.
Example 22Enhancement of the ALTER TABLESPACE statement
postgres=# ALTER TABLESPACE ts1 SET (effective_io_concurrency = 2) ;
ALTER TABLESPACE
postgres=# \db+ ts1
List of tablespaces
Name | Owner | Location | Access privileges |
Options | Size | Description
------+-------+--------------------+-------------------+--------------
----------+--------+-------------
ts1 | demo | /home/postgres/ts1 | |
{effective_io_concurrency=2} | 472 kB |
(1 row)
3.4.4 Enhancement of the CREATE EXTENSION statement
To CREATE EXTENSION statement, CASCADE clause to automatically load the relevant module can now be specified. Syntax
CREATEEXTENSIONmodule_name[CASCADE]
PDF page 30
Example 23CREATE EXTENSION CASCADE statement
postgres=# CREATE EXTENSION earthdistance ;
ERROR: required extension "cube" is not installed
HINT: Use CREATE EXTENSION CASCADE to install required extensions too.
postgres=#
postgres=# CREATE EXTENSION earthdistance CASCADE ;
NOTICE: installing required extension "cube"
CREATE EXTENSION
postgres=#
3.4.5 Enhancement of the ALTER OPERATOR statement
ALTER OPERATOR statement to make the change of the operator have been significantly enhanced. It can be added use the following syntax as well as the CREATE OPERATOR statement. Syntax
Following function have been enhanced in PostgreSQL 9.6.
scale function
By specifying a number of numeric type as the parameter, this function returns the number of decimal places. It cannot be used for a float type value. If NULL is passed, it returns NULL.
num_nulls / num_nonnulls functions
Returns the number of NULL values from any number of arguments (num_nulls), returns the number of non-NULL value (num_nonnulls).
The overloaded function that has second parameter has been created. When specified true for the second parameter, no error occurs if specified a non-existent parameter.
It is now possible to get the information by SQL function, conventionally that has been acquired by the pg_controldata command by SQL function. The following functions can be used. General users can use these functions.
Function Name
Description
pg_control_init
Acquiring of database cluster information
pg_control_checkpoint
Acquiring of checkpoint information
pg_control_recovery
Acquiring of recovery information
Table 21Added functions
PDF page 33
Example 27Execute pg_control_init function
postgres=> \x
Expanded display is on.
postgres=> SELECT * FROM pg_control_init() ;
-[ RECORD 1 ]--------------+---------
max_data_alignment | 8
database_block_size | 8192
blocks_per_segment | 131072
wal_block_size | 8192
bytes_per_wal_segment | 16777216
max_identifier_length | 64
max_index_columns | 32
max_toast_chunk_size | 1996
large_object_chunk_size | 2048
bigint_timestamps | t
float4_pass_by_value | t
float8_pass_by_value | t
data_page_checksum_version | 0
postgres=> \x
Expanded display is on.
postgres=> SELECT * FROM pg_control_recovery() ;
-[ RECORD 1 ]-----------------+----
min_recovery_end_location | 0/0
min_recovery_end_timeline | 0
backup_start_location | 0/0
backup_end_location | 0/0
end_of_backup_record_required | f
PDF page 35
pg_current_xlog_flush_location function
Function pg_current_xlog_flush_location that returns the LSN indicating the writing location of the WAL file has been added. General users can execute this function, but cannot execute in slave instance of the replication environment.
This function decompose a string indicating the name of the object that contains the schema name into an array consists of schema and object names. The presence of the specified object is not checked. Also search_path parameter is not considered.
Pg_size_bytes function returns the number of bytes from the string specified in units of kB, MB, GB and TB. This is the opposite behavior of pg_size_pretty function. It can be put a space between the number and the unit.