PostgreSql初探(2)-创建数据库
1.创建数据库 createdb 是一个 SQL 命令 CREATE DATABASE的封装,和在psql里通过create database mydb效果是一样的 2.访问数据库 mydb=# mydb=# select version();
version ---------------------------------------------------------------------------------------------------------------
PostgreSQL 9.4.4 on x86_64-unknown-linux-gnu,compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48),64-bit
(1 row)
mydb=# select version()
不加‘;’的话不会像oracle与mysql一样等待你输入‘;’ psql程序有一些不属于SQL命令的内部命令,他们以‘’开头 mydb=# help
You are using psql,the command-line interface to PostgreSQL.
Type: copyright for distribution terms
h for help with SQL commands
? for help with psql commands
g or terminate with semicolon to execute query
q to quit
mydb-# h
Available help:
ABORT CREATE FOREIGN DATA WRAPPER DROP SEQUENCE ALTER AGGREGATE CREATE FOREIGN TABLE DROP SERVER ALTER COLLATION CREATE FUNCTION DROP TABLE ALTER CONVERSION CREATE GROUP DROP TABLESPACE ALTER DATABASE CREATE INDEX DROP TEXT SEARCH CONFIGURATION ALTER DEFAULT PRIVILEGES CREATE LANGUAGE DROP TEXT SEARCH DICTIONARY ALTER DOMAIN CREATE MATERIALIZED VIEW DROP TEXT SEARCH PARSER ALTER EVENT TRIGGER CREATE OPERATOR DROP TEXT SEARCH TEMPLATE ALTER EXTENSION CREATE OPERATOR CLASS DROP TRIGGER ALTER FOREIGN DATA WRAPPER CREATE OPERATOR FAMILY DROP TYPE ALTER FOREIGN TABLE CREATE ROLE DROP USER ALTER FUNCTION CREATE RULE DROP USER MAPPING ALTER GROUP CREATE SCHEMA DROP VIEW ALTER INDEX CREATE SEQUENCE END ALTER LANGUAGE CREATE SERVER EXECUTE ALTER LARGE OBJECT CREATE TABLE EXPLAIN ALTER MATERIALIZED VIEW CREATE TABLE AS FETCH ALTER OPERATOR CREATE TABLESPACE GRANT --More--
sql命令的帮助信息 mydb=# ?
General
copyright show PostgreSQL usage and distribution terms
g [FILE] or ; execute query (and send results to file or |pipe)
gset [PREFIX] execute query and store results in psql variables
h [NAME] help on syntax of SQL commands,* for all commands
q quit psql
watch [SEC] execute query every SEC seconds
Query Buffer
e [FILE] [LINE] edit the query buffer (or file) with external editor
ef [FUNCNAME [LINE]] edit function definition with external editor
p show the contents of the query buffer
r reset (clear) the query buffer
s [FILE] display history or save it to file
w FILE write query buffer to file
Input/Output
copy ... perform SQL COPY with data stream to the client host
echo [STRING] write string to standard output
--More--
psql命令的帮助信息 mydb-# q 关于plsql的详细内容可以看文档http://www.postgres.cn/docs/9.3/app-psql.html testdb=>set PROMPT1 ‘%n@%m %~%R%# ‘ peter@localhost testdb=> You can display tables in different ways by using the pset command: peter@localhost testdb=>pset border 2Border style is 2.
peter@localhost testdb=>SELECT * FROM my_table;+-------+--------+
| first | second |
+-------+--------+
| 1 | one |
| 2 | two |
| 3 | three |
| 4 | four |
+-------+--------+
(4 rows)
peter@localhost testdb=>pset border 0Border style is 0.
peter@localhost testdb=>SELECT * FROM my_table;first second
----- ------
1 one
2 two
3 three
4 four
(4 rows)
peter@localhost testdb=>pset border 1Border style is 1.
peter@localhost testdb=>pset format unalignedOutput format is unaligned.
peter@localhost testdb=>pset fieldsep ","Field separator is ",".
peter@localhost testdb=>pset tuples_onlyShowing only tuples.
peter@localhost testdb=>SELECT second,first FROM my_table;one,1
two,2
three,3
four,4
通过pset改变输出格式 Alternatively,use the short commands: peter@localhost testdb=>a t xOutput format is aligned.
Tuples only is off.
Expanded display is on.
peter@localhost testdb=>SELECT * FROM my_table;-[ RECORD 1 ]-
first | 1
second | one
-[ RECORD 2 ]-
first | 2
second | two
-[ RECORD 3 ]-
first | 3
second | three
-[ RECORD 4 ]-
first | 4
second | four
x Expanded display
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |