赞
踩
(1 ) 注意增加约束时的写法,和ORACLE 略有不同
Oracle :
ALTER TABLE SCHEMA.PREFIX_INFO ADD (
CONSTRAINT PK_PREFIX_INFO PRIMARY KEY (INFO_ID));
alter table schema.prefix_info add constraint prefix_info_pkey primary key(info_id);
(2 )系统默认的最大值与ORACLE 不同
Oracle :
CREATE SEQUENCE PREFIX_INFO_SEQUENCE
INCREMENT BY 1
START WITH 582
MINVALUE 1
MAXVALUE 9999999999999999999999999999
NOCYCLE
CACHE 20
NOORDER;
PostgresQL :
CREATE SEQUENCE schema.prefix_info_sequence
increment 1
minvalue 1
maxvalue 9223372036854775807
start 582
cache 20;
(3 )PostgresQL 中的 || 用 法与其他数据库不同:
select a|| b from table1;
当a 或b 其中一个为null 时, 该查询返回null ,
(4 )PostgresQL 中没有concat 函数,且由于|| 用法的问题,无法使用|| 替换,解决 方法为在public schema 中创建函数concat
create or replace function concat(text, text)
returns text as
$body$select coalesce($1,'') || coalesce($2,'')$body$
language 'sql' volatile;
alter function concat(text, text) owner to postgres;
-- 无需特殊授权即可在其他schema 中使用
(4 )PostgresQL 中没有dual 虚拟表,为保 证程序兼容性,可创建伪视图(view )替代:
CREATE OR REPLACE VIEW dual AS
SELECT NULL::"unknown"
WHERE 1 = 1;
ALTER TABLE dual OWNER TO postgres;
GRANT ALL ON TABLE dual TO postgres;
GRANT SELECT ON TABLE dual TO public;
必须授权public 以select 权 限
(5 )关联查询用法区别
ORACLE:
简单外连接:
SELECT COUNT(DISTINCT(A.COL1)) AS RCOUNT from
SCHEMA.PREFIX_TABLE1 A,SCHEMA.PREFIX_TABLE2 B
WHERE 1 = 1
AND A.COL2 = B.COL2(+)
AND A.COL3 > 0
AND A.COL4 = '1'
超级变态外连接:
SELECT COUNT(DISTINCT(A.COL1)) AS RCOUNT from
SCHEMA.PREFIX_TABLE1 A,SCHEMA.PREFIX_TABLE2 B,SCHEMA.PREFIX_TABLE3 C,SCHEMA.PREFIX_TABLE4 D
WHERE 1 = 1
AND A.COL2 = B.COL2
AND A.COL3 = C.COL3(+)
AND A.COL4 = D.COL4(+)
AND A.COL5 > 0
AND A.COL6 = '1'
POSTGRESQL:
简单外连接:
select count(distinct(a.col1)) as rcount from
schema.prefix_table1 a left ou
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。