Friday, July 23, 2010

Postgres array

select * from company where company_code in ('103','001')

select * from company where company_code = any(array['103','001'])

select * from company where company_code = any( regexp_split_to_array('103,001', ',') )

-- very neat, no need to to split string to array, can cast string directly to array, as long there's curly bracket inside
select * from company where company_code = any('{103,001}'::text[])


Friday, July 16, 2010

Nested function/subroutine in C#



This is how we simulate nested function in C# :

Friday, July 9, 2010

Debugging Form_Load while inside VS IDE is impossible

private void Form1_Load(object sender, EventArgs e)
{
 int n = 0;
 int i = 7 / n; // this fail silently while inside Visual Studio
}

private void button1_Click(object sender, EventArgs e)
{
 int n = 0;
 int i = 7 / n;
}

Friday, July 2, 2010

Unboxing, Casting

int totalPage = (int)(long)cmdCount.ExecuteScalar();

That is not double casting. The first(read from right to left) cast, is actually unboxing, we unbox long from object, then cast the long type to int type

Unboxing shares the same syntax of casting

Thursday, July 1, 2010

Proper indexing for (hidden) tuples











If you have a query like this:

select * from zd
where z in
(select z from zh where y = 'A' and y = zd.y)

It is recommended to index on both y,z fields of both zh and zd tables

create index x_zh on zh(y,z)
create index x_zd on zd(y,z)