PostgreSQL index size and value number

pg_table_size(‘index_name’) for individual index – but it only shows you the size on disk, not the number of entries. count(*) to get the exact current number of rows sum(pg_column_size(column_name)) from table_name for estimations on column data size. You can try something like: t=# \di+ tbl* List of relations Schema | Name | Type | Owner … Read more

“extra data after last expected column” while trying to import a csv file into postgresql

Now you have 7 fields. You need to map those 6 fields from the CSV into 6 fields into the table. You cannot map only 3 fields from csv when you have it 6 like you do in: \COPY agency (agency_name, agency_url, agency_timezone) FROM ‘myFile.txt’ CSV HEADER DELIMITER ‘,’; All fields from the csv file … Read more

Refresh a materialized view automatically using a rule or notify

You should refresh the view in triggers after insert/update/delete/truncate for each statement on table1 and table2. create or replace function refresh_mat_view() returns trigger language plpgsql as $$ begin refresh materialized view mat_view; return null; end $$; create trigger refresh_mat_view after insert or update or delete or truncate on table1 for each statement execute procedure refresh_mat_view(); … Read more

Check if a Postgres JSON array contains a string

As of PostgreSQL 9.4, you can use the ? operator: select info->>’name’ from rabbits where (info->’food’)::jsonb ? ‘carrots’; You can even index the ? query on the “food” key if you switch to the jsonb type instead: alter table rabbits alter info type jsonb using info::jsonb; create index on rabbits using gin ((info->’food’)); select info->>’name’ … Read more

postgresql list and order tables by size

select table_name, pg_relation_size(quote_ident(table_name)) from information_schema.tables where table_schema=”public” order by 2 This shows you the size of all tables in the schema public if you have multiple schemas, you might want to use: select table_schema, table_name, pg_relation_size(‘”‘||table_schema||'”.”‘||table_name||'”‘) from information_schema.tables order by 3 SQLFiddle example: http://sqlfiddle.com/#!15/13157/3 List of all object size functions in the manual.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)