Jakis czas temu pisalem o mojej przygodzie na Wegrzech i “jazdach" z HDI. Dzis inna historyjka/przypowiesc, nt. firmy “Inter Partner Assistance" i BRE Leasing.
Waiting for 8.4 – TABLE
On Thursday, 20th of November, Peter Eisentraut committed his own patch, which adds new command to PostgreSQL: TABLE.
While this command doesn't do anything that wasn't available earlier, it's worth mentioning, as it's one of patches that make PostgreSQL compatible with SQL:2008.
Basically new command “TABLE" acts like an alias to ‘SELECT * FROM':
Waiting for 8.4 – auto-explain
On 19th of November Tom Lane committed patch by Takahiro Itagaki which does:
Add auto-explain contrib module for automatic logging of the plans of slow-running queries.
Designing database for storing human-human relations
Absolutely great post about designing database schema to contain information about marriages and partnerships with emphasis on changes brought to us by modern day – gay marriages, non-trivial sex/gender identities and polygamy.
Waiting for 8.4 – array aggregate and array unpacker
Finally, we got very important addons to PostgreSQL, which help with dealing with arrays.
It solves a lot of problems, which were usually solved with standard cookbook code, which was in faqs, blog posts and number of examples on irc.
Continue reading Waiting for 8.4 – array aggregate and array unpacker
Waiting for 8.4 – suppress_redundant_updates_trigger
On 3rd of November Andrew Dunstan committed his patch which adds new function to PostgreSQL – suppress_redundant_updates_trigger().
This function is not for using in selects, but it can help you tremendously if your database access matches certain pattern.
Continue reading Waiting for 8.4 – suppress_redundant_updates_trigger
Waiting for 8.4 – sql-wrappable RETURNING
In PostgreSQL 8.2, we got “RETURNING" clause in INSERT/UPDATE/DELETE queries.
Unfortunately it could not be used as source of rows for anything in sql.
insert into table_backup delete from table where ... returning *;
Well, it's still not possible, but it is a one step closer, thanks to patch written and committed by Tom Lane on 31st of October:
Allow SQL-language functions to return the output of an INSERT/UPDATE/DELETE RETURNING clause, not just a SELECT as formerly. A side effect of this patch is that when a set-returning SQL function is used in a FROM clause, performance is improved because the output is collected into a tuplestore within the function, rather than using the less efficient value-per-call mechanism.
Waiting for 8.4 – pl/* srf functions in selects
On 28th of October Tom Lane committed his patch that changes some internals of functions, but it also adds interesting capability.
Continue reading Waiting for 8.4 – pl/* srf functions in selects
Tips N’ Tricks – setting field based on order
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 update first 3 records (ordered by id) to have following values in priority:
- 10000
- 5000
- 1000
Continue reading Tips N’ Tricks – setting field based on order
Is there any good versioning package for database schema and/or data?
Like practically any application, applications that I deal with evolve. They change their requirements when it comes to database storage – new tables, new columns, modified columns. Or perhaps – new base data – like new values in virtually static dictionaries.
For past years we've been working with set of pl/plgsql functions which kept track of “patches", and their dependencies.
The problem with this approach is that it doesn't really scale well, and it generates problems when we use replication (Slony).
The problems mean that we have to apply the patches “by hand" on master/slave server, because downtime in the day is not acceptable, and nobody is willing to do upgrades at 3 am just to be able to add new column.
So, we deal with it. But lately I grew annoyed by this, and started to think about a better way to organize patches.
I “dream" about a system when I would write a patch itself, and the system will make it possible to install and uninstall it with automatic changing database to prior state (this is not simple with things like “update", but it is definitely possible).
System which would “understand" replication, and apply changes to all replicated servers in a way that it will be as safe as possible with no or minimal downtime.
System which would let me track dependencies, and then install them if I'll tell it to install patch, that requires some other patches that were not applied to target database.
Basically – I want something like apt-get/dpkg/rpm for database.
So, writing this seems to be perfectly possible, but is it necessary? Perhaps somebody someplace already wrote such system? Do you know any? Or should I stop whining, sit down and write it myself?