One of the questions that gets asked quite a lot, is: how can you use variables in your queries? Other databases have them, does PostgreSQL? Actually the answer is “no”. But, it is actually very easy to work around, and what’s more important – quite often, what you need are not variables in queries, but … Continue reading “Variables in SQL, what, how, when?”
In PostgreSQL 8.4 we got CTE – Common Table Expressions. Since then we have this great tool available, but apparently for some people it’s still black magic. CuTE, but still magic. I’ll try to make it a bit less magical, and more understandable.
Some of you might be familiar with pgBouncer project. Some are not. Some understand what/how/why it does, others do not. This blog post is to have a place where I can point people who have question about how it works, why, and when it makes sense to use it (pgBouncer that is).
And maybe not on the wall, but instead in your SQLz, eating your data. But a bit more seriously. Ever since PostgreSQL 8.4 we have window functions, but still I see people which do not know it or are wary to use it. That’s why I decided to write a piece on window functions. How … Continue reading “Window, window on the wall …”
Some people are afraid of triggers. Reasons for this are not really understandable for me, but I guess it stems from the fact that these are usually application developers, and not database admins. Or they encountered some kind of problem with triggers, and now they tend to think that triggers are inherently evil. But they … Continue reading “How I Learned to Stop Worrying and Love the Triggers”
Yesterday on irc someone asked: Hi, how do I get top 5 values from a column group by another column?? From further discussion, I learned that: total rows in table is 2 million. It’ll have unique words of less than 1 million.. (approx count) I didn’t have time yesterday, but decided to write a solution, … Continue reading “Getting top-N rows per group”
As I wrote earlier, we (my wife and me) went to Maldives. This is brief summary, with some photos below.
For various reasons, and in various cases, bloat happens. Theoretically autovacuum protects us all, but sometimes it doesn’t. Sometimes someone disables it, or mis-configures, or bad planet alignment happens, and we end up in deep bloat. What to do then? Vacuum? Vacuum Full? Cluster? No. pg_reorg!
Every so often someone asks why sorting behaves irrational. Like here: $ SELECT string FROM test ORDER BY string; string ———- dean deer de luca depesz de vil dyslexia (6 ROWS) Why aren’t “de luca” and “de vil” together?
Some time ago I wrote about getting fast pagination. While fast, it had some problems which made it unusable for some. Specifically – you couldn’t get page count, and easily jump to page number N. I did some thinking on the subject, and I think I found a way to make it all work. Quite … Continue reading “Pagination with fixed order”