Added all automatically created and changed files for version 0.3.0.

parent 146121de
......@@ -17,6 +17,14 @@ conversions have become more strict.
All examples have been done with PostgreSQL 10, differences in the behaviour of
previous versions are noted.
# Repositories
The main repository is now on
[GitLab](https://gitlab.com/sjstoelting/pgsql-tweaks.git). A mirror will stay on
[GitHub](https://github.com/sjstoelting/pgsql-tweaks).
If you discover any issue, please file them on
https://gitlab.com/sjstoelting/pgsql-tweaks/issues.
# Building the extension
......@@ -89,7 +97,8 @@ Afterwards you are able to create the extension in a database:
1.3.2 [VIEW pg_db_views](#VIEW.pg_db_views)<br />
1.3.3 [VIEW pg_foreign_keys](#VIEW.pg_foreign_keys)<br />
1.3.4 [VIEW pg_functions](#VIEW.pg_functions)<br />
1.3.4 [VIEW pg_active_locks](#VIEW.pg_active_locks)
1.3.4 [VIEW pg_active_locks](#VIEW.pg_active_locks)<br />
1.3.5 [VIEW pg_table_matview_infos](#VIEW.pg_table_matview_infos)
1.4 [Functions about encodings](#Functions.about encodings)<br />
1.4.1 [FUNCTION is_encoding](#FUNCTION.is_encoding)<br />
......@@ -119,6 +128,9 @@ Afterwards you are able to create the extension in a database:
1.7 [Conversion functions](#Conversion.functions)<br />
1.7.1 [FUNCTION to_unix_timestamp](#FUNCTION.to_unix_timestamp)
1.8 [Other functions](#Other.functions)<br />
1.8.1 [FUNCTION array_trim](#FUNCTION.array_trim)
# List of functions
## Functions to check data types
......@@ -693,7 +705,7 @@ Creates a function which returns a SHA256 hash for the given string.<br />
The parameter has to be converted into a binary string of [bytea](https://www.postgresql.org/docs/current/static/datatype-binary.html).</br>
:heavy_exclamation_mark:<span style="color:red">The function needs the [pgcrypto](https://www.postgresql.org/docs/current/static/pgcrypto.html) package</span>:heavy_exclamation_mark:
:heavy_exclamation_mark:This function is not part of the package because of the external dependencies.:heavy_exclamation_mark:
:heavy_exclamation_mark:This function has an external dependencies and is only installed, if the package pgcrypto is installed:heavy_exclamation_mark:
#### Example
......@@ -811,6 +823,9 @@ SELECT * FROM pg_foreign_keys;
Creates a view to get all functions of the current database, excluding those in the schema pg_catalog and information_schema.
As there have been changes to the system tables used in this view, there are now two scripts dependend on the PostgreSQL version on which it has to be used,
one for PostgreSQL 11 or newer and one for PostgreSQL 10 or older. This is handled in the script that creates the view.
```sql
SELECT * FROM pg_functions;
```
......@@ -837,6 +852,21 @@ Result:
| 8872 | active | chinook | stefanie | psql | 127.0.0.1 | 2018-02-18 14:45:53.943047+01 | | | relation | AccessShareLock | SELECT * FROM pg_active_locks; |
| 8872 | active | chinook | stefanie | psql | 127.0.0.1 | 2018-02-18 14:45:53.943047+01 | | | virtualxid | ExclusiveLock | SELECT * FROM pg_active_locks; |
### VIEW pg_table_matview_infos
Creates a view with information about the size of the table/materialized view and sizes of indexes on that table/materialized view.
It does also list all indexes on that table in an array.
```sql
SELECT * FROM pg_table_matview_infos;
```
Result:
| type | schemaname | tablename | tableowner | tablespace | indexes | table_size | indexes_size | total_relation_size | table_size_pretty | indexes_size_pretty | total_relation_size_pretty |
| ---- | ---------- | --------- | ---------- | ---------- | ------- | ----------:| ------------:| -------------------:| -----------------:| -------------------:| --------------------------:|
| table | public | MediaType | stefanie | [NULL] | {PK_MediaType} | 8192 | 16384 | 24576 | 8192 bytes | 16 kB | 24 kB |
| table | public | Playlist | stefanie | [NULL] | {PK_Playlist} | 8192 | 16384 | 24576 | 8192 bytes | 16 kB | 24 kB |
## Functions about encodings
......@@ -1516,3 +1546,46 @@ Result:
| unix_timestamp |
| --------------:|
| 1514761200 |
## Other functions
### FUNCTION array_trim
Removes empty strings and null entries from a given array. In addition the
function can remove duplicate entries. The function supports strings, numbers,
dates, and timestamps with or without time zone.
#### Examples
```sql
-- Untrimmed timestamp array with time zone with duplicates
SELECT array_trim(ARRAY['2018-11-11 11:00:00 MEZ',NULL,'2018-11-11 11:00:00 MEZ']::TIMESTAMP WITH TIME ZONE[]) AS trimmed_array;
```
Result:
| untrimmed_array |
| ------------------------------------------------------ |
| {'2018-11-11 11:00:00.000',,'2018-11-11 11:00:00.000'} |
```sql
-- Timestamp array with time zone with duplicates
SELECT ARRAY['2018-11-11 11:00:00 MEZ',NULL,'2018-11-11 11:00:00 MEZ']::TIMESTAMP WITH TIME ZONE[] AS untrimmed_array;
```
Result:
| trimmed_array |
| ----------------------------------------------------- |
| {'2018-11-11 11:00:00.000','2018-11-11 11:00:00.000'} |
```sql
-- Timestamp array with time zone without duplicates
SELECT array_trim(ARRAY['2018-11-11 11:00:00 MEZ',NULL,'2018-11-11 11:00:00 MEZ']::TIMESTAMP WITH TIME ZONE[], TRUE) AS trimmed_array_distinct;
```
Result:
| trimmed_array_distinct |
| --------------------------- |
| {'2018-11-11 11:00:00.000'} |
This diff is collapsed.
This diff is collapsed.
/*** uninstall file to drop all objects created by the extension pgsql_tweaks ***/
BEGIN;
DROP VIEW IF EXISTS pg_active_locks;
DROP FUNCTION IF EXISTS is_empty(s VARCHAR);
DROP FUNCTION IF EXISTS array_sum(a BIGINT[]);
DROP FUNCTION IF EXISTS array_sum(a INTEGER[]);
DROP FUNCTION IF EXISTS array_sum(a SMALLINT[]);
DROP FUNCTION IF EXISTS array_sum(a REAL[]);
DROP FUNCTION IF EXISTS array_sum(a DOUBLE PRECISION[]);
DROP FUNCTION IF EXISTS array_sum(a NUMERIC[]);
DROP FUNCTION IF EXISTS array_avg(a BIGINT[]);
DROP FUNCTION IF EXISTS array_avg(a INTEGER[]);
DROP FUNCTION IF EXISTS array_avg(a SMALLINT[]);
DROP FUNCTION IF EXISTS array_avg(a REAL[]);
DROP FUNCTION IF EXISTS array_avg(a DOUBLE PRECISION[]);
DROP FUNCTION IF EXISTS array_avg(a NUMERIC[]);
DROP FUNCTION IF EXISTS array_min(a TEXT[]);
DROP FUNCTION IF EXISTS array_min(a BIGINT[]);
DROP FUNCTION IF EXISTS array_min(a INTEGER[]);
DROP FUNCTION IF EXISTS array_min(a SMALLINT[]);
DROP FUNCTION IF EXISTS array_min(a REAL[]);
DROP FUNCTION IF EXISTS array_min(a DOUBLE PRECISION[]);
DROP FUNCTION IF EXISTS array_min(a NUMERIC[]);
DROP FUNCTION IF EXISTS array_max(a TEXT[]);
DROP FUNCTION IF EXISTS array_max(a BIGINT[]);
DROP FUNCTION IF EXISTS array_max(a INTEGER[]);
DROP FUNCTION IF EXISTS array_max(a NUMERIC[]);
DROP FUNCTION IF EXISTS array_max(a REAL[]);
DROP FUNCTION IF EXISTS array_max(a DOUBLE PRECISION[]);
DROP FUNCTION IF EXISTS array_max(a SMALLINT[]);
DROP FUNCTION IF EXISTS array_trim(a VARCHAR[], rd BOOLEAN);
DROP FUNCTION IF EXISTS array_trim(a SMALLINT[], rd BOOLEAN);
DROP FUNCTION IF EXISTS array_trim(a INTEGER[], rd BOOLEAN);
DROP FUNCTION IF EXISTS array_trim(a BIGINT[], rd BOOLEAN);
DROP FUNCTION IF EXISTS array_trim(a NUMERIC[], rd BOOLEAN);
DROP FUNCTION IF EXISTS array_trim(a REAL[], rd BOOLEAN);
DROP FUNCTION IF EXISTS array_trim(a DOUBLE PRECISION[], rd BOOLEAN);
DROP FUNCTION IF EXISTS array_trim(a DATE[], rd BOOLEAN);
DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP[], rd BOOLEAN);
DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP WITH TIME ZONE[], rd BOOLEAN);
DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp with time zone);
DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp);
DROP FUNCTION IF EXISTS datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN);
DROP FUNCTION IF EXISTS date_de(d DATE);
DROP AGGREGATE IF EXISTS gap_fill(anyelement);
DROP FUNCTION IF EXISTS gap_fill_internal(s anyelement, v anyelement);
DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]);
DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, replacement VARCHAR);
DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR);
DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]);
DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR, replacement VARCHAR);
DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR);
DROP FUNCTION IF EXISTS return_not_part_of_encoding(s VARCHAR, e VARCHAR);
DROP FUNCTION IF EXISTS return_not_part_of_latin1(s VARCHAR);
DROP FUNCTION IF EXISTS is_latin1(s VARCHAR);
DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR, enc_from VARCHAR);
DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR);
DROP VIEW IF EXISTS pg_functions;
DROP VIEW IF EXISTS pg_foreign_keys;
DROP VIEW IF EXISTS pg_db_views;
DROP VIEW IF EXISTS pg_table_matview_infos;
DROP FUNCTION IF EXISTS pg_schema_size(text);
DROP FUNCTION IF EXISTS sha256(bytea);
DROP FUNCTION IF EXISTS is_bigint(s VARCHAR);
DROP FUNCTION IF EXISTS is_integer(s VARCHAR);
DROP FUNCTION IF EXISTS is_smallint(s VARCHAR);
DROP FUNCTION IF EXISTS is_numeric(s VARCHAR);
DROP FUNCTION IF EXISTS is_real(s VARCHAR);
DROP FUNCTION IF EXISTS is_double_precision(s VARCHAR);
DROP FUNCTION IF EXISTS is_boolean(s VARCHAR);
DROP FUNCTION IF EXISTS is_json(s VARCHAR);
DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR, f VARCHAR);
DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR);
DROP FUNCTION IF EXISTS is_time(s VARCHAR, f VARCHAR);
DROP FUNCTION IF EXISTS is_time(s VARCHAR);
DROP FUNCTION IF EXISTS is_date(s VARCHAR, f VARCHAR);
DROP FUNCTION IF EXISTS is_json(s VARCHAR);
DROP FUNCTION IF EXISTS is_jsonb(s VARCHAR);
END;
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment