开源不等于免费,Mysql就是榜样。但PostgreSQL,我认为是唯一的开源、免费、并且符合商业应用要求的关系性数据库系统。我在Unix下做了100万级的数据处理,效果让我非常满意,从那以后我都向用户建议如果用于非大规模的仓储数据,都应该采用PostgreSQL做为数据存储方法。

Money数据格式

[不指定 2007/12/22 22:16 | by fubin ]
CREATE TABLE employee (
ID         int,
name       varchar(10),
salary     real,
start_date date,
city       varchar(10),
region     char(1)
);

insert into employee (ID, name,    salary, start_date, city,       region) values (1,  'Jason', 40420,  '02/01/94', 'New York', 'W');
insert into employee (ID, name,    salary, start_date, city,       region)values (2,  'Robert',14420,  '01/02/95', 'Vancouver','N');

SELECT salary * 100 AS New_Salary,to_char(salary * 100, '$99,999,999.9999999') AS monetary, translate(to_char(salary * 100, '$99,999,999.9999999'),' ','') AS translated FROM employee ;

显示不同货币不同格式。
Tags:

PostGreSQL基础:比较String

[不指定 2007/12/18 08:55 | by fubin ]
PostGreSQL提供了一个非常有意思的函数:substr

例如:

SELECT name FROM employee WHERE substr(name, 1, 1) < 'D';

以上的意思是:name字段1个字母开始到第1个字母结束的的字符串和'D'比较,显示小于D的部分。也就是说只显示开头是a,b,c的内容。
Tags:

PostGreSQL基础:游标的使用

[不指定 2007/12/17 08:39 | by fubin ]
完整例子:


建表:

CREATE TABLE employee (
ID         int,
name       varchar(10),
salary     real,
start_date date,
city       varchar(10),
region     char(1)
);

加入数据:


insert into employee (ID, name,    salary, start_date, city,       region)values (1,  'Jason', 40420,  '02/01/94', 'New York', 'W');
insert into employee (ID, name,    salary, start_date, city,       region)values (2,  'Robert',14420,  '01/02/95', 'Vancouver','N');
insert into employee (ID, name,    salary, start_date, city,       region)values (3,  'Celia', 24020,  '12/03/96', 'Toronto',  'W');
insert into employee (ID, name,    salary, start_date, city,       region)values (4,  'Linda', 40620,  '11/04/97', 'New York', 'N');
insert into employee (ID, name,    salary, start_date, city,       region)values (5,  'David', 80026,  '10/05/98', 'Vancouver','W');
insert into employee (ID, name,    salary, start_date, city,       region)values (6,  'James', 70060,  '09/06/99', 'Toronto',  'N');
insert into employee (ID, name,    salary, start_date, city,       region)values (7,  'Alison',90620,  '08/07/00', 'New York', 'W');
insert into employee (ID, name,    salary, start_date, city,       region)values (8,  'Chris', 26020,  '07/08/01', 'Vancouver','N');
insert into employee (ID, name,    salary, start_date, city,       region)values (9,  'Mary',  60020,  '06/09/02', 'Toronto',  'W');

开始实验:

begin work;
DECLARE all_employees CURSOR FOR SELECT * FROM employee;
-- Fetching rows from a cursor
FETCH 4 FROM all_employees;
FETCH NEXT FROM all_employees;
commit work;

从以上例子可以看出,FETCH NEXT是取得最后一条的,而FETCH 4是取得前四条的。
Tags:

PostgreSQL支持Boolean型数据

[阴 2007/11/14 00:01 | by fubin ]
    PostgreSQL是支持Boolean型数据格式的。

  例如:

  CREATE TABLE test1 (a boolean, b text);    
   INSERT INTO test1 VALUES (TRUE, 'sic est');
   INSERT INTO test1 VALUES (FALSE, 'non est');

     但是这里要提醒开发者的是,在PostgreSQL提供的JDBC中对Boolean型数据变量支持是比较弱的,需要认真阅读以后才可以使用,有很多情况是被禁止使用的。


   SELECT * FROM test1 WHERE NOT a;

     结果就会只出现false的值,Not代表false.
Tags:

关于PostgreSQL栏目

[阴 2007/11/11 23:43 | by fubin ]
      其实我想建这个栏目很久了,但是由于时间有限,如果我建太多栏目维护起来恐怕不是很方便,所以一直就搁置着,这几天由于朋友的几个电信级别应用找我帮其建议数据库解决方案,我欣然建议他们使用PostgreSQL。我认为如果在Unix下使用,PostgreSQL是最好的中等数据库解决方案。

   但是我帮他写具体的建设方案的时候我发现,PostgreSQL对我来说已经有些陌生啦,为了把这个陌生的老朋友找回来,我决定建立这个栏目。
分页: 1/1 第一页 [1] 最后页 [ 显示模式: 摘要 | 列表 ]