原文在这
http://www.oschina.net/bbs/thread/15088
大虾们多指点,感觉这是个难题。
http://www.oschina.net/bbs/thread/15088
大虾们多指点,感觉这是个难题。
解决方案 »
- Mysql 免安装版的配置问题
- 2个sql语句合并成一条查询
- linux下的MYSQL
- 请教MYSQL对于某个账号指定2个IP段访问,如何解决?
- MySQL双机镜像备份问题
- win下mysql管理密码忘了怎么办?
- mysql查询中文不精确怎么办? 比如='nono'会出现='洋洋'的记录.
- 未入门者的几个Postgresql的简单问题。
- 我的开发环境:delphi 7, mysql 4.0.18, myodbc 3.51
- 使用同一条件字段,不同条件值,速度慢了很多,求解!
- 对供货商的名字进行模糊搜索,想找出他的商品的名字和价格
- PostgreSQL在执行update、insert、delete时是操作写磁盘的操作?
iihero=# CREATE FUNCTION one() RETURNS integer
iihero-# AS 'SELECT 1 as ONE' LANGUAGE SQL;
CREATE FUNCTION
iihero=# SELECT one() AS answer;
answer
1
(1 row)
iihero=# \encoding gbk
iihero=# SELECT one() AS answer;
answer
--------
1
(1 row)
iihero=# CREATE TABLE EMP (
iihero(# name text,
iihero(# salary integer,
iihero(# age integer,
iihero(# cubicle point
iihero(# );
CREATE TABLE
iihero=# INSERT INTO EMP VALUES ('Sam', 1200, 16, '(1,1)');
INSERT 0 1
iihero=# INSERT INTO EMP VALUES ('Claire', 5000, 32, '(1,2)');
INSERT 0 1
iihero=# INSERT INTO EMP VALUES ('Andy', -1000, 2, '(1,3)');
INSERT 0 1
iihero=# INSERT INTO EMP VALUES ('Bill', 4200, 36, '(2,1)');
INSERT 0 1
iihero=# INSERT INTO EMP VALUES ('Ginger', 4800, 30, '(2,4)');
INSERT 0 1
iihero=#
iihero=# CREATE FUNCTION double_salary(EMP) RETURNS integer
iihero-# AS 'SELECT $1.salary * 2 AS salary' LANGUAGE SQL;
CREATE FUNCTION
iihero=# SELECT name, double_salary(EMP) AS dream
iihero-# FROM EMP
iihero-# WHERE EMP.cubicle ~= '(2,1)'::point;
name | dream
------+-------
Bill | 8400
(1 row)
iihero=# CREATE FUNCTION add_one(integer) RETURNS integer as 'func1' LANGUAGE C;
CREATE FUNCTION
iihero=# CREATE FUNCTION makepoint(point, point) RETURNS point
iihero-# AS 'func1' LANGUAGE C;
CREATE FUNCTION
iihero=# CREATE FUNCTION copytext(text) RETURNS text
iihero-# AS 'func1' LANGUAGE C;
CREATE FUNCTION
iihero=#
iihero=# CREATE FUNCTION c_overpaid(EMP, integer) RETURNS boolean
iihero-# AS 'func1' LANGUAGE C;
CREATE FUNCTION
iihero=# select add_one(3) as four;
four
------
4
(1 row)
iihero=# SELECT makepoint('(1,2)'::point, '(3,4)'::point ) AS newpoint;
newpoint
----------
(1,4)
(1 row)
iihero=# SELECT copytext('hello world!');
copytext
--------------
hello world!
(1 row)
iihero=# SELECT name, c_overpaid(EMP, 1500) AS overpaid
iihero-# FROM EMP
iihero-# WHERE name = 'Bill' or name = 'Sam';
name | overpaid
------+----------
Sam | f
Bill | t
(2 rows)中间创建函数用的func1.dll,你要把它编译到目录pgsql_home\lib下边。必须是MD(多线程链接库)方式。
整个过程很简单。使用vs2005编译即可。
你稍后在我的资源里头应该能下载到完整的工程,比较简单的。我已经上传了。
PostgreSQL简单函数创建: http://download.csdn.net/source/2979577