вторник, 29 марта 2011 г.

"Raising Elephants" mnemonic device

The section was removed from Wiki with the following comment: Removed section. I strongly feel it doesn't belong. There's no magic formula and REISUB doesn't seem like a good idea either.

I do not think so. So here is the removed section:

---
A common idiom to perform a safe reboot of a Linux computer which has otherwise locked up, the QWERTY (or AZERTY) mnemonic "Raising Elephants Is So Utterly Boring", "Reboot Even If System Utterly Broken" or simply remembering the word "BUSIER" backwards, is often useful. It stands for:
unRaw       
 tErminate 
 kIll       
  Sync     
  Unmount  
reBoot.
This can prevent a fsck being required on reboot and gives some programs a chance to save emergency backups of unsaved work.
In practice, each command may require a few seconds to complete, especially if feedback is unavailable from the screen due to a freeze or display corruption. For example, sending SIGKILL to processes which have not yet finished terminating can cause data loss.
---

среда, 23 марта 2011 г.

Преобразование varchar в integer в Postgres на лету.

Для подобного преобразования достаточно определить следующую функцию:

db=> CREATE FUNCTION toint(varchar)
RETURNS integer
STRICT IMMUTABLE LANGUAGE SQL AS
'SELECT cast($1 as integer);';
db=> \d public.items
Column | Type
-----------------------+------------------------
...
description | character varying(255)
...
lastvalue | character varying(255)
...
db=> select sum(lastvalue) from public.items where description like '%YOUR ITEM%' and lastvalue is not null;
ERROR: function sum(character varying) does not exist
LINE 1: select sum(lastvalue) from public.items where description li...
db=> select sum(toint(lastvalue)) from public.items where description like '%YOUR ITEM%' and lastvalue is not null;
sum
-------
100000
(1 row)
view raw gistfile1.sql hosted with ❤ by GitHub

Источник решения: stackoverflow.com.