机试失败了,给的是window 2003server的机器,postgre
sql 9.3,现在都习惯用ubuntu了自家笔记本都是ubuntu,以后面试不知道怎么办,回来参考postgre
sql官方文档一小时不到就全
解决了,说实在的我真没接触过postgre
sql的存储过程,要我看着别人的
代码模仿写真痛苦,尤其是没一点pg
sql的语法基础,废话不说上题目和答案(说的是招聘JAVA结果全面的postgre
sql汗颜。。。) 环境ubuntu,postgre
sql 9.3 1.恢复pg_dump的
输出文件 p
sql create user mianshi superuser login createdb password 'mianshi' create tablespace mianshi_ts owner mianshi location '/windows/data/pgdata' create database mianshi owner=mianshi tablespace=mianshi_ts \q p
sql -h localhost -U mianshi \i mianshi.bak 2.postgre
sql 递归实现 create table tb_tree(id int,pid int,name varchar(8000)); insert into tb_tree values(1,null,'祖父'),(2,1,'父亲'),(3,2,'本人'),(4,'弟弟'); with RECURSIVE t(id,pid,name) as (select * from tb_tree where name='本人' union all select tb_tree.* from tb_tree,t where tb_tree.id=t.pid) select * from t; 3.计算一个时间的年龄 select age(timestamp '1985-05-15 5:5:5'); 4.计算两个时间距离的天数 select current_date - (timestamp '2014-2-27 1:1:1')::date; 5.计算两个时间间隔的秒数 select extract(epoch from current_timestamp - (timestamp '2014-2-27 1:1:1')::date); 6.创建存储过程使用for遍历某个表 create or replace function mianshi_func01() returns void as $$ declare --l_id tb_tree.id%type; --l_pid tb_tree.pid%type; --l_name tb_tree.name%type; l_record RECORD; begin for l_record in select * from tb_tree loop raise info 'ID%,父ID%,
名称%',l_record.id,l_record.pid,l_record.name; end loop; end; $$ language plpg
sql; 7.使用游标遍历某个表 create or replace function mianshi_func02() returns void as $$ declare l_id tb_tree.id%type; l_pid tb_tree.pid%type; l_name tb_tree.name%type; l_cursor cursor for select * from tb_tree; begin open l_cursor; fetch l_cursor into l_id,l_pid,l_name; while found loop raise info 'ID%,l_id,l_name; fetch l_cursor into l_id,l_name; end loop; close l_cursor; end; $$ language plpg
sql; 8.备份
数据库完成后
删除数据库 pg_dump -f another.bak mianshi drop database mianshi;
原文链接:https://www.f2er.com/postgresql/195858.html