Postgresql 中文操作指南
2.1. Introduction #
本章概述了如何使用 SQL 执行简单操作。本教程仅旨在为您提供简介,绝不是 SQL 的完整教程。已经编写了大量有关 SQL 的书籍,包括 [id="melt93",role="bare"]biblio.html#MELT93[id="melt93"] 和 [id="date97",role="bare"]biblio.html#DATE97[id="date97"]。您应当知道,某些 PostgreSQL 语言功能是对标准的扩展。
This chapter provides an overview of how to use SQL to perform simple operations. This tutorial is only intended to give you an introduction and is in no way a complete tutorial on SQL. Numerous books have been written on SQL, including biblio.html#MELT93 and biblio.html#DATE97. You should be aware that some PostgreSQL language features are extensions to the standard.
在以下示例中,我们假设您已根据上一章所述创建名为 mydb 的数据库,并且能够启动 psql。
In the examples that follow, we assume that you have created a database named mydb, as described in the previous chapter, and have been able to start psql.
本手册中的示例还可在目录 src/tutorial/ 中的 PostgreSQL 源代码分发版中找到。(PostgreSQL 的二进制分发版可能不提供这些文件。)要使用这些文件,请首先切换到该目录并运行 make:
Examples in this manual can also be found in the PostgreSQL source distribution in the directory src/tutorial/. (Binary distributions of PostgreSQL might not provide those files.) To use those files, first change to that directory and run make:
$ cd .../src/tutorial
$ make
这将创建脚本并编译包含用户定义函数和类型的 C 文件。然后,执行以下操作以启动本教程:
This creates the scripts and compiles the C files containing user-defined functions and types. Then, to start the tutorial, do the following:
$ psql -s mydb
...
mydb=> \i basics.sql
\i 命令从指定文件中读取命令。psql 的 -s 选项可让您进入单步模式,该模式在将每个语句发送到服务器之前暂停。本节中使用的命令位于 basics.sql 文件中。
The \i command reads in commands from the specified file. psql's -s option puts you in single step mode which pauses before sending each statement to the server. The commands used in this section are in the file basics.sql.