PostgreSQL: преобразование строки в число

В базе данных доступны следующие строки:

Исходные данные

Требуется в колонке c_house_number, которая является типом text, найти число и сохранить преобразованное значение в новой колонке:

Читать далее «PostgreSQL: преобразование строки в число»

Создание временной таблицы в PostgreSQL

    --  список ТУ заданной РЭС
create temp table t_registr_pts (
    id uuid,
    c_registr_pts text,
    f_status_consume int,
    b_technical_metering bool,
    f_subscr uuid,
    f_address uuid,
    c_ps text,
    c_line_ps text,
    c_rp text,
    c_line_rp text,
    c_tp text,
    c_line_tp text,
    c_raion text,
    c_city_name text,
    c_settlement_name text,
    c_street_name text
) on commit drop;

How to track query progress in PostgreSQL?

I found a good answer here: Tracking progress of an update statement

The trick is to first create a sequence (name it as you like):

CREATE SEQUENCE query_progress START 1;

Then append to your query’s WHERE part:

AND NEXTVAL('query_progress')!=0

Now you can query the progress:

SELECT NEXTVAL('query_progress');

Finally don’t forget to get rid of the sequence:

DROP SEQUENCE query_progress;

Note that this will most likely make your query run even slower and every time you check progress it will additionally increment the value. The above link suggested creating a temporary sequence but PostgreSQL doesn’t seem to make them visible across sessions.

How to track query progress in PostgreSQL? — Stack Overflow

Выполнение SQL в postgres

do
$$
declare
    _f_user int = 63; -- это идентификатор пользователя из таблицы core.pd_users: 63 - Милютин, 59 - Телегин
    _d_date timestamptz = now();
    _n_longitude numeric(19, 6) = 47.2279506;
    _n_latitude numeric(19, 6) = 56.1484872;
    _c_network_status text = 'online';
begin
    insert into core.ad_tracking (fn_user, d_date, n_longitude, n_latitude, c_network_status)
    values(_f_user, _d_date, _n_longitude, _n_latitude, _c_network_status);
end;
$$
language plpgsql;

Как узнать размер таблиц в postgresql

SELECT nspname || '.' || relname AS "relation", pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size" 
FROM pg_class C 
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) 
WHERE nspname NOT IN ('pg_catalog', 'information_schema') AND C.relkind <> 'i' AND nspname !~ '^pg_toast' 
ORDER BY pg_total_relation_size(C.oid) DESC 
LIMIT 100;

Обслуживание PostgreSql

Examples

In the examples below, [tablename] is optional. Without a table specified, VACUUM will be run on available tables in the current schema that the user has access to.

  1. Plain VACUUM: Frees up space for re-use
VACUUM [tablename]
  1. Full VACUUM: Locks the database table, and reclaims more space than a plain VACUUM
/* Before Postgres 9.0: */ 
VACUUM FULL 
/* Postgres 9.0+: */ 
VACUUM(FULL) [tablename]
  1. Full VACUUM and ANALYZE: Performs a Full VACUUM and gathers new statistics on query executions paths using ANALYZE
/* Before Postgres 9.0: */ 
VACUUM FULL ANALYZE [tablename] 
/* Postgres 9.0+: */ 
VACUUM(FULL, ANALYZE) [tablename]
  1. Verbose Full VACUUM and ANALYZE: Same as #3, but with verbose progress output
/* Before Postgres 9.0: */ 
VACUUM FULL VERBOSE ANALYZE [tablename] 
/* Postgres 9.0+: */ 
VACUUM(FULL, ANALYZE, VERBOSE) [tablename]
Читать далее «Обслуживание PostgreSql»