Monday, November 16, 2009

plpgsql style



CREATE OR REPLACE function _getSchema(_table text) RETURNS integer AS $$

DECLARE

_record RECORD;
_column TEXT;
_type TEXT;

BEGIN
RAISE NOTICE 'select ';

FOR _record in
SELECT column_name,data_type from information_schema.columns where table_name = _table

LOOP

_column := _record.column_name;
_type := _record.data_type;

IF
_record.data_type = 'text'
THEN
RAISE NOTICE 'count(distinct(%)) as dist_%,', _column, _column;
ELSIF
_record.data_type = 'numeric' or _record.data_type = 'integer'
THEN
RAISE NOTICE 'sum (%) as sum_%,', _column, _column;
END IF;

END LOOP;

RAISE NOTICE 'count (*) as rows';
RAISE NOTICE 'from % ', _table;


RETURN 0;

END;
$$ LANGUAGE 'plpgsql';

Saturday, November 14, 2009

get basic stats from a table.


$arPgUser = array("user"=> "postgres","host"=>"localhost","dbname"=>"dev","password" => "i1m2a3p4o5o6p7e8r9");
$connStr = getConnStr($arPgUser);
$conn = pg_connect($connStr);
$table = "books";

$sqlGetSchema = "select column_name,data_type from information_schema.columns where table_name = '{$table}'";
$res = pg_fetch_all(pg_query($conn,$sqlGetSchema));
$columns = array_map("sqlFieldStats",($res));

$sqlBuildStats= sqlBuildStats($columns,$table);
$res = pg_fetch_all(pg_query($conn,$sqlBuildStats));
print_r($res);

pg_close($conn);

function sqlBuildStats($columns,$table){

$sqlColumns = implode(",\n",$columns);
$sql = "
select
$sqlColumns
from
$table
";
echo "{$sql}\n";

return trim($sql);
}

function sqlFieldStats($arSchema){

switch($arSchema['data_type']){

case "text":
return "count(distinct({$arSchema['column_name']})) as dist_{$arSchema['column_name']}";
break;

case "numeric":
return "sum({$arSchema['column_name']}) as sum_{$arSchema['column_name']}";
break;
}
}


function getConnStr($arPgUser){

$connStr = "";
foreach ($arPgUser as $key => $value)
$connStr.= "{$key} = {$value} ";

return $connStr;
}

Friday, October 2, 2009

Check the sound.






Powered By TheirToys.com
Get Your OwnAdult Tracker

Monday, February 16, 2009

What an electro day.


A mash of
Tanya Stephen's - What a day
and
dutty dubz - Electro


Download

Smoking Wet.


My Dnb playlist mixed.

(00:00) . Street Life : chase and status
(03:07) . Believe : chase and status
(06:18) . Take me away : chase and status
(11:05) . Can it be so simple : concept and shnek
(13:28) . Rumors : mutt
(15:43) . 2 strike back : zero tolerance and beta
(18:21) . Supastar : concept and shnek
(21:39) . Bedford avenue (feat dj. crum) concept and shnek
(24:35) . Try to get away : dj clart
(28.50) . These words : dj clart
(31:47) . The motions : mutt
(36:02) . La cinta : Utah jazz
(39.21) . Funkless life : Utah jazz
(41.33) . Feeling inside : Utah jazz
(43:51) . In love (feat jenna) g : chase and status
(47:57) . Session and superking : Walk away
(51:10) . Soul musiq (feat. youngman) : atlantic connection
(54:18) . Here for you : Bassface sascha and franksen


Download -> http://www.sendspace.com/file/ay6rnl

Sunday, November 16, 2008

The system told me.


An stepping tune
of Joker's - Stuck in the system
and the Killer's - Somebody told me.


Download