↑↓ 选择 ↵ 打开 ⌫ 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

不受支持的版本: 7.0 / 6.3
历史版本PostgreSQL 6.3 已于 2003 年 3 月结束社区维护,本页译文保留供仍在使用旧版本的读者参考。新系统请看当前版本手册首页。

18.3. 玩转 Postgres

在 Postgres 安装完成、数据库系统创建好、postmaster 守护进程在运行、回归测试通过之后,你会想看看 Postgres 做点什么。这很容易。调用 Postgres 的交互界面 psql:

    % psql template1

(psql 必须打开一个特定的数据库,但此时唯一存在的是 template1 数据库,它总是存在的。我们连接到它只是为了创建另一个数据库然后切换过去。)

psql 的响应是:

Welcome to the POSTGRESQL interactive sql monitor:
  Please read the file COPYRIGHT for copyright terms of POSTGRESQL

   type \? for help on slash commands
   type \q to quit
   type \g or terminate with semicolon to execute query
 You are currently connected to the database: template1

template1=>

创建数据库 foo:

template1=> create database foo;
CREATEDB

(养成写上 SQL 分号的习惯。在看到分号或 "\g" 之前 psql 不会执行任何东西,而且分号是分隔多条语句所必需的。)

现在连接到新数据库:

template1=> \c foo
connecting to new database: foo

("斜杠"命令不是 SQL,所以不用分号。用 \? 可以看到所有斜杠命令。)

再创建一个表:

foo=> create table bar (i int4, c char(16));
CREATE

然后查看新表:

foo=> \d bar

Table    = bar
+----------------------------------+----------------------------------+-------+
|              Field               |              Type                | Length|
+----------------------------------+----------------------------------+-------+
| i                                | int4                             |     4 |
| c                                | (bp)char                         |    16 |
+----------------------------------+----------------------------------+-------+

依此类推。你明白意思了。

提交更正

译文有误、术语不当或页面显示问题,请到译文仓库 pgsty/pgdoc 报告译文问题。 英文原文本身的问题,请在当前版本的对应页面向上游反馈;上游不再修订已结束维护的版本。