PostgreSQL sql放入文件批量执行
来源:互联网 发布:tekla钢结构软件下载 编辑:程序博客网 时间:2024/05/09 06:54
PostgreSQL sql放入文件,登入数据库之后批量执行
1. 建立测试sql:
vi aa.sql
插入:猜测每条sql语句是用;分隔的,function中的多个;也会自动识别。
create table tb1(id integer);
insert into tb1 select generate_series(1,10);
select * from tb1;
delete from
tb1 where id<3;
select * from tb1;
2. 将aa.sql放入 ./src/postgresql-9.3.5/src/tutorial下(./src/postgresql-9.3.5/src/tutorial是PostgreSQL自动识别的目录,当然也可以放在任意目录,比如/home/postgres/aa.sql)
3. 切换用户登入
su postgres
psql postgres
4. 执行:当输入\i时候,会自动检测到./src/postgresql-9.3.5/src/tutorial下的文件,PostgreSQL的测试例子也放在此目录下
postgres=# \i aa.sql (\i /home/postgres/aa.sql) id | name ----+------ 1 | join 2 | join 3 | join 4 | join 5 | join 6 | join 7 | join 8 | join 9 | join 10 | join(10 rows)CREATE TABLEINSERT 0 10 id ---- 1 2 3 4 5 6 7 8 9 10(10 rows)DELETE 2 id ---- 3 4 5 6 7 8 9 10(8 rows)postgres=#
postgres=# \d tb1 Table "public.tb1" Column | Type | Modifiers --------+---------+----------- id | integer |
第二个例子:
vi bb.sql:
写入一个function:
create function func1()returns void as $$declarebegindelete from person where id>5;delete from tb1 where id>5;end$$language plpgsql;select func1();切换到postgres,登入之后执行:
执行前:
postgres=# select * from person ; id | name ----+------ 1 | join 2 | join 3 | join 4 | join 5 | join 6 | join 7 | join 8 | join 9 | join 10 | join(10 rows)postgres=# select * from tb1 ; id ---- 3 4 5 6 7 8 9 10(8 rows)执行:
postgres=# \i bb.sql CREATE FUNCTION func1 ------- (1 row)
执行后:
postgres=# select * from person ; id | name ----+------ 1 | join 2 | join 3 | join 4 | join 5 | join(5 rows)postgres=# select * from tb1 ; id ---- 3 4 5(3 rows)postgres=#
5. 也可以使用psql命令执行
pslq -d postgres -U postgres -f /home/postgres/aa.sql
0 0
- PostgreSQL sql放入文件批量执行
- postgreSQL 终止正在执行的SQL
- Postgresql通过批处理命令执行sql文件
- Postgresql查看SQL语句执行效率
- (SQL)如何将exec执行结果放入外面的变量中--动态sql
- 如何将exec执行结果放入外面的变量中--动态sql
- PostgreSQL SQL的性能调试方法3--查看执行计划
- 执行SQL取PostgreSQL数据库或表大小
- postgresql中如何Kill掉正在执行的SQL语句
- PostgreSQL SQL的性能调试方法3--查看执行计划
- PostgreSQL调出每一次sql执行所花的时间
- PostgreSQL 使用anto_explain自动记录超时SQL的执行计划
- postgresql中查看操作执行的具体sql语句
- postgresql导出sql执行结果到文件的方法
- 多postgresql库批量执行SQL脚本文件
- 查看PostgreSQL数据库中SQL语句的执行计划
- PostgreSQL SQL的性能调试方法 查看执行计划
- PostgreSQL 设置单条SQL的执行超时
- Dijkastra算法求最短路径
- H.264笔记之一
- c语言取整方法
- hdu1686
- android 3des加密Access restriction: The constructor SunJCE() is not accessible due to restrictio
- PostgreSQL sql放入文件批量执行
- 从最简单的实例学习ARM 指令集(五)
- 【java编程】IO特殊类之RandomAccessFile实现多线程文件下载
- WeifenLuo.WinFormsUI.Docking.dll的用法
- js心得-jquery EasyUI之datagrid合并单元格
- Xcode联机调试错误”failed to get the task for process XXX”的解决办法
- Activity 横竖屏幕切换的几种实现方式
- 聚集创建
- 七层协议介绍