赞
踩
COPY [ BINARY ] table [ WITH OIDS ]
FROM { 'filename' | stdin }
[ [USING] DELIMITERS 'delimiter' ]
[ WITH NULL AS 'null string' ]
COPY [ BINARY ] table [ WITH OIDS ]
TO { 'filename' | stdout }
[ [USING] DELIMITERS 'delimiter' ]
[ WITH NULL AS 'null string' ]
<attr1><separator><attr2><separator>...<separator><attrn><newline>
COPY country TO stdout USING DELIMITERS '|';
COPY country FROM '/usr1/proj/bray/sql/country_data';
AF AFGHANISTAN
AL ALBANIA
DZ ALGERIA
ZM ZAMBIA
ZW ZIMBABWE
/.
0000000 P G B C O P Y /n 377 /r /n /0 004 003 002 001
0000020 /0 /0 /0 /0 /0 /0 /0 /0 003 /0 377 377 006 /0 /0 /0
0000040 A F 377 377 017 /0 /0 /0 A F G H A N I S
0000060 T A N /0 /0 003 /0 377 377 006 /0 /0 /0 A L 377
0000100 377 /v /0 /0 /0 A L B A N I A /0 /0 003 /0
0000120 377 377 006 /0 /0 /0 D Z 377 377 /v /0 /0 /0 A L
0000140 G E R I A /0 /0 003 /0 377 377 006 /0 /0 /0 Z
0000160 M 377 377 /n /0 /0 /0 Z A M B I A /0 /0 003
0000200 /0 377 377 006 /0 /0 /0 Z W 377 377 /f /0 /0 /0 Z
0000220 I M B A B W E /0 /0 377 377
Caution
|
如果用语序列对象的cache 设置大于一, 而且该对象可能被多个后端同时使用就有可能产生不可预料的结果.每个后端 在访问过序列对象并递增序列对象的 last_value 后, 将分配跟在序列值后面"缓存数".这样,该后端在下面的cache-1 次nextval调用将使用预分配好的数值, 而不对共享对象做任何更新. 所以,任何已经分配但在会话中没有使用的数字 将在会话结束时丢失.而且,尽管多个后端保证分配独立的序列值, 当考虑所有的后端时该数值却有可能是乱序的.(例如,设置cache为10, 后端 A 可能保留数值 1..10 并且返回nextval=1, 而后端 B 可能保留数值 11..20 并在后端 A 生成nextval=2 之 前返回 nextval=11.)因此, 将cache 设为一可以安全地假设nextval的数值是顺序生成的; 当缓存数设置大于一,我 们只能假设nextval值都是独立的, 而不能假设它们都是纯粹顺序生成的. 同样,last_value将反映由任何后端保留的最 后数值,不管它是不是nextval曾返回过的. 另外一个问题是在这样的序列上执行的 setval 将不会被 其它后端知晓,直道它们用光所有预先分配的缓存数值.
|
DROP VIEW name [, ...]
DROP VIEW kinds;
DROP VIEW view { RESTRICT | CASCADE }
SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]
* | expression [ AS output_name ] [, ...]
[ FROM from_item [, ...] ]
[ WHERE condition ]
[ GROUP BY expression [, ...] ]
[ HAVING condition [, ...] ]
[ { UNION | INTERSECT | EXCEPT } [ ALL ] select ]
[ ORDER BY expression [ ASC | DESC | USING operator ] [, ...] ]
[ FOR UPDATE [ OF tablename [, ...] ] ]
[ LIMIT { count | ALL } ]
[ OFFSET start ]
这里 from_item 可以是:
[ ONLY ] table_name [ * ]
[ [ AS ] alias [ ( column_alias_list ) ] ]
|
( select )
[ AS ] alias [ ( column_alias_list ) ]
|
from_item [ NATURAL ] join_type from_item
[ ON join_condition | USING ( join_column_list ) ]
SELECT DISTINCT ON (location) location, time, report
FROM weatherReports
ORDER BY location, time DESC;
WHERE boolean_expr
expr cond_op expr
log_op expr
GROUP BY expression [, ...]
HAVING boolean_expr
ORDER BY expression [ ASC | DESC | USING operator ] [, ...]
SELECT title, date_prod + 1 AS newlen FROM films ORDER BY newlen;
SELECT name FROM distributors ORDER BY code;
table_query UNION [ ALL ] table_query
[ ORDER BY expression [ ASC | DESC | USING operator ] [, ...] ]
[ LIMIT { count | ALL } [ { OFFSET | , } start ]]
table_query INTERSECT [ ALL ] table_query
[ ORDER BY expression [ ASC | DESC | USING operator ] [, ...] ]
[ LIMIT { count | ALL } ]
[ OFFSET start ]
table_query EXCEPT [ ALL ] table_query
[ ORDER BY expression [ ASC | DESC | USING operator ] [, ...] ]
[ LIMIT { count | ALL } ]
[ OFFSET start ]
LIMIT { count | ALL }
OFFSET start
SELECT f.title, f.did, d.name, f.date_prod, f.kind
FROM distributors d, films f
WHERE f.did = d.did
title | did | name | date_prod | kind
---------------------------+-----+------------------+------------+----------
The Third Man | 101 | British Lion | 1949-12-23 | Drama
The African Queen | 101 | British Lion | 1951-08-11 | Romantic
Une Femme est une Femme | 102 | Jean Luc Godard | 1961-03-12 | Romantic
Vertigo | 103 | Paramount | 1958-11-14 | Action
Becket | 103 | Paramount | 1964-02-03 | Drama
48 Hrs | 103 | Paramount | 1982-10-22 | Action
War and Peace | 104 | Mosfilm | 1967-02-12 | Drama
West Side Story | 105 | United Artists | 1961-01-03 | Musical
Bananas | 105 | United Artists | 1971-07-13 | Comedy
Yojimbo | 106 | Toho | 1961-06-16 | Drama
There's a Girl in my Soup | 107 | Columbia | 1970-06-11 | Comedy
Taxi Driver | 107 | Columbia | 1975-05-15 | Action
Absence of Malice | 107 | Columbia | 1981-11-15 | Action
Storia di una donna | 108 | Westward | 1970-08-15 | Romantic
The King and I | 109 | 20th Century Fox | 1956-08-11 | Musical
Das Boot | 110 | Bavaria Atelier | 1981-11-11 | Drama
Bed Knobs and Broomsticks | 111 | Walt Disney | | Musical
(17 rows)
SELECT kind, SUM(len) AS total FROM films GROUP BY kind;
kind | total
----------+-------
Action | 07:34
Comedy | 02:58
Drama | 14:28
Musical | 06:42
Romantic | 04:38
(5 rows)
SELECT kind, SUM(len) AS total
FROM films
GROUP BY kind
HAVING SUM(len) < INTERVAL '5 hour';
kind | total
----------+-------
Comedy | 02:58
Romantic | 04:38
(2 rows)
SELECT * FROM distributors ORDER BY name;
SELECT * FROM distributors ORDER BY 2;
did | name
-----+------------------
109 | 20th Century Fox
110 | Bavaria Atelier
101 | British Lion
107 | Columbia
102 | Jean Luc Godard
113 | Luso films
104 | Mosfilm
103 | Paramount
106 | Toho
105 | United Artists
111 | Walt Disney
112 | Warner Bros.
108 | Westward
(13 rows)
distributors: actors:
did | name id | name
-----+-------------- ----+----------------
108 | Westward 1 | Woody Allen
111 | Walt Disney 2 | Warren Beatty
112 | Warner Bros. 3 | Walter Matthau
... ...
SELECT distributors.name
FROM distributors
WHERE distributors.name LIKE 'W%'
UNION
SELECT actors.name
FROM actors
WHERE actors.name LIKE 'W%'
name
----------------
Walt Disney
Walter Matthau
Warner Bros.
Warren Beatty
Westward
Woody Allen
SELECT 2+2;
?column?
----------
4
SELECT distributors.* WHERE distributors.name = 'Westward';
did | name
-----+----------
108 | Westward
SELECT distributors.* FROM distributors d;
SELECT d.* FROM distributors d;
SELECT distributors.* FROM distributors d, distributors distributors;
table_query UNION [ALL]
[CORRESPONDING [BY (column [,...])]]
table_query
设置 PGDATESTYLE 环境变量. 如果一个基于 libpq 的客户端的环境里设置了 PGDATESTYLE, libpq 将在联接启动时自动把DATESTYLE 设置成为 PGDATESTYLE 的值。
|
用-o -e参数运行 postmaster可以把日期设置成 European.
|
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。