If you have production DB servers, chances are you're running variant of these queries: SELECT sum(pg_relation_size(oid)) from pg_class where relkind = 'i' SELECT sum(pg_relation_size(oid)) from pg_class where relkind = 'r' To get summarized size of tables and/or indexes in your database (for example ...
Every now and then I need a function that returns nothing. As you perhaps know, even defining function as "RETURNS VOID" doesn't fully solve the problem:
I'm quite often doing stuff on remote machines, and quite frequently I start some long-running job, when I remember that I didn't ran it via screen - so it will break, if my network connection will die. Is there any sane ...
Every so often you might need to find a value regardless of which column it's in. Of course not in application code, as this would be very slow. But you might be in situation where you just don't know where did ...
I got asked this: having this table: # select * from a order by d; t | d ---+---- O | 1 O | 2 O | 3 M | 4 M | 5 M ...
More than once I've seen situation when there is a table, with serial primary key, and rows contain also some kind of creation timestamp, which is usually monotonic, or close to monotonic. Example of such case are for example comments or ...
Let's say you imported some data, but it contains duplicates. You will have to handle them in some way, but to make sensible choice on how to handle it, you need more information. So, let's start. We have table: # \d users ...
Let's imagine following situation: create table test (id int4 primary key, priority int4); insert into test (id) select distinct (random() * 100000000)::int4 from generate_series(1,1000); Table test will now contain some (up to 1000) records, with random ids. Now, we want to ...
Let's assume you have very simple table with users: # \d users Table "public.users" ...
cortilap @ freenode's #postgresql asked about how to create a check() that will allow only one of the columns to be not null. it doesn't sound cool, let's see: with 2 columns (a,b) you make a check: check ( (a is not ...
