Showing posts with label POSTGRES. Show all posts
Showing posts with label POSTGRES. Show all posts

Sunday, April 1, 2012

SQL- distinct

select distinct city, college_name from students

> so the combination of city and college should be distinct we can not have it like

select city, distinct college_name from students

but we can have it with an aggregate e.g. for each city give me the count of distinct colleges :) eh!

select city, count(distinct college_name) from students

postgres - from clause in update sql

update students set college_name = c.name from colleges c
where students.city = c.city

weired SQL but awesome isn't??!!

> In update we cannot use aliases for the update table so have to use the full name in case of ambiguous columns e.g. city

> we can have any number of from tables with aliases and have a join on the update table and also can update a value using a value from the join table

Friday, November 11, 2011

Installing PNP


I am working on Ubuntu (Debian)

echo 'Installing PHP...';
sudo apt-get install --yes --force-yes php5-cli php5-dev php5-fpm php5-pgsql php5-mcrypt php5-gd php5-curl php-pear

echo 'Installing nginx...';
sudo apt-get --yes --force-yes install nginx


echo 'Installing Postgres...';
sudo add-apt-repository ppa:pitti/postgresql
echo 'Updating...';
sudo apt-get --yes --force-yes update
echo 'Upgrading...';
sudo apt-get --yes --force-yes dist-upgrade
echo 'Installing postgres...';
sudo apt-get --yes --force-yes install postgresql-plpython-9.1