Tuesday, December 11, 2007

postgresql adventure: part 3, a bit on the sql

Actually I did this sometime ago for my ruby on rails experiment. On my ubuntu machine

To start on creating the database, on postgres, as I said before, is very unlike mysql. In mysql, it is calling createdb on mysql shell. On postgres, you call on shell:
createdb databasename
if something happen and you want to drop it, it is done by calling
dropdb databasename
then you call
psql databasename
here i assume, that you create a user, in postgresql server that is your name. Suppose the above command doesn't doesn't work, do this, which I only tested on ubuntu, on other you might need to login as postgres user:
sudo -u postgres psql
now you can create tables, which again, very different from mysql. With many similarity as well.
in the psql shell, create table like this:
create table contact(
id serial primary key,
name varchar(255),
address text,
email varchar(255)
);
Which very similar with mysql, except, why id is serial?
Well, it turn out that, there is no autoincrement on postgresql, but it have a serial, which is really an autoincrementing integer. So that's interesting.

Actually this is just the very surface of postgresql sql. Actually, there is many features, that mysql don't have or have it very recently. such as
- inheritance, you can, inherit from another table, ala oop. mysql don't have that
- procedural language, which mysql, introduced stored procedure in mysql 5. not too long ago.

I barely touch this, so there is more adventure for me in the future

No comments:

Post a Comment