PostgreSQL学习第八篇--psql的使用技巧和注意事项
2016-11-28 14:42
525 查看
1.历史命令与补全功能 可以使用上下键把以前使用过的命令或SQL语句调出来。 连续按两个tab键表示命令补全或者提示输入。--类似于Linux功能 2.自动提交方面的技巧 在psql中,事务是自动提交的。(与oracle不同) 如果不想自动提交,可以: 默认,postgresql是自动提交的,可以避免自动提交 1)使用begin;命令 示例: postgres=# begin; BEGIN postgres=# insert into test values(2,2); INSERT 0 1 postgres=# select * from test; id | name ----+------ 1 | 1 | 2 2 | 2 (3 行记录) postgres=# rollback; ROLLBACK postgres=# select * from test; id | name ----+------ 1 | 1 | 2 (2 行记录) 2)还可以直接关闭自动提交的功能 \set AUTOCOMMIT off --注意,AUTOCOMMIT要大写。 示例: postgres=# \set AUTOCOMMIT off postgres=# postgres=# postgres=# insert into test values(2,2); INSERT 0 1 postgres=# select * from test; id | name ----+------ 1 | 1 | 2 2 | 2 (3 行记录) postgres=# rollback; ROLLBACK postgres=# select * from test; id | name ----+------ 1 | 1 | 2 (2 行记录) 3.得到psql命令行中具体执行的SQL语句 启动psql时加上-E参数,或者在命令行中使用\set ECHO_HIDDEN on|off命令。 [postgres@single ~]$ psql -E psql (9.6.1) Type "help" for help. postgres=# \d ********* QUERY ********** SELECT n.nspname as "Schema", c.relname as "Name", CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' WHEN 'f' THEN 'foreign table' END as "Type", pg_catalog.pg_get_userbyid(c.relowner) as "Owner" FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('r','v','m','S','f','') AND n.nspname <> 'pg_catalog' AND n.nspname <> 'information_schema' AND n.nspname !~ '^pg_toast' AND pg_catalog.pg_table_is_visible(c.oid) ORDER BY 1,2; ************************** List of relations Schema | Name | Type | Owner --------+------+-------+---------- public | test | table | postgres public | txx | table | postgres (2 rows) postgres=# \set ECHO_HIDDEN off postgres=# \d List of relations Schema | Name | Type | Owner --------+------+-------+---------- public | test | table | postgres public | txx | table | postgres (2 rows) postgres=# \set ECHO_HIDDEN on postgres=# \d ********* QUERY ********** SELECT n.nspname as "Schema", c.relname as "Name", CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' WHEN 'f' THEN 'foreign table' END as "Type", pg_catalog.pg_get_userbyid(c.relowner) as "Owner" FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('r','v','m','S','f','') AND n.nspname <> 'pg_catalog' AND n.nspname <> 'information_schema' AND n.nspname !~ '^pg_toast' AND pg_catalog.pg_table_is_visible(c.oid) ORDER BY 1,2; ************************** List of relations Schema | Name | Type | Owner --------+------+-------+---------- public | test | table | postgres public | txx | table | postgres (2 rows)
相关文章推荐
- MED-V使用教程之四技巧注意事项 推荐
- PostgreSQL使用注意事项
- Android Studio的一些技巧和使用注意事项(持续更新)
- JavaScript中this关键词的使用技巧、工作原理以及注意事项
- windows下使用postgresql8.01的几个注意事项
- 学习:使用SPSite和SPWeb对象要注意的事项(转)
- C++学习笔记(二):使用const、static类成员的注意事项
- MySQLDUMP注意事项&使用技巧
- php学习笔记(三十四)smarty框架的初步使用和注意事项
- MySQL索引类型总结和使用技巧以及注意事项
- 学习:使用SHAREPOINT对象模型开发时注意事项(转)
- Windows Azure服务购买,收费,使用注意事项及学习资料推荐
- [学习笔记]寄存器使用注意事项
- 使用ADS1.2的注意事项及常用技巧
- 使用 Input Type="File" 的一些技巧和注意事项(添加中)
- PostgreSQL使用注意事项
- Windows Azure服务购买,收费,使用注意事项及学习资料推荐
- Windows Azure服务购买,收费,使用注意事项及学习资料推荐
- C++学习之使用new的注意事项
- C++学习之使用new的注意事项