70.4. Команды BKI

create имя_таблицы oid_таблицы [bootstrap] [shared_relation] [rowtype_oid oid] (имя1 = тип1 [FORCE NOT NULL | FORCE NULL] [, имя2 = тип2 [FORCE NOT NULL | FORCE NULL], ...])

Создать таблицу имя_таблицы с заданным oid_таблицы и столбцами, указанными в скобках.

Непосредственно bootstrap.c поддерживает следующие типы столбцов: bool, bytea, char (1 байт), name, int2, int4, regproc, regclass, regtype, text, oid, tid, xid, cid, int2vector, oidvector, _int4 (массив), _text (массив), _oid (массив), _char (массив), _aclitem (массив). Хотя возможно создать таблицы, содержащие столбцы и других типов, это нельзя сделать, пока не будет создан и заполнен соответствующими записями каталог pg_type. (По сути это означает, что только эти типы столбцов могут быть в каталогах начальной загрузки, хотя другие каталоги могут содержать любые встроенные типы.)

С указанием bootstrap таблица будет создана только на диске; никакие записи о ней не будут добавлены в pg_class, pg_attribute и т. д. Таким образом, таблица не будет доступна для обычных операций SQL, пока такие записи не будут добавлены явно (командами insert). Это указание применяется для создания самой структуры pg_class и подобных ей.

Если добавлено указание shared_relation, таблица создаётся как общая. Дополнительным предложением rowtype_oid может быть задан OID типа строки (OID записи в pg_type); если он не указан, OID генерируется автоматически. (Предложение rowtype_oid бесполезно, если присутствует указание bootstrap, но его всё равно можно добавить для документирования.)

open имя_таблицы

Открыть таблицу имя_таблицы для добавления данных. Любая другая таблица, открытая в данный момент, закрывается.

close имя_таблицы

Закрыть открытую таблицу. Имя таблицы должно задаваться для перепроверки.

insert ( [значение_oid] значение1 значение2 ... )

Вставить строку в открытую таблицу с именами столбцов значение1, значение2 и т. д.

Значения NULL могут задаваться специальным ключевым словом _null_. Значения, отличные от идентификаторов и цифровых строк, должны заключаться в двойные кавычки.

declare [unique] index имя_индекса oid_индекса on имя_таблицы using имя_метода_доступа ( класс_оп1 имя1 [, ...] )

Создать индекс имя_индекса с OID, равным oid_индекса, в таблице имя_таблицы, с методом доступа имя_метода_доступа. Индекс строится по полям имя1, имя2 и т. д., и для них используются соответственно классы операторов класс_оп1, класс_оп2 и т. д. Эта команда создаёт файл индекса и добавляет соответствующие записи в каталог, но не инициализирует содержимое индекса.

declare toast oid_таблицы_toast oid_индекса_toast on имя_таблицы

Создаёт таблицу TOAST для таблицы имя_таблицы. Таблице TOAST назначается OID, равный oid_таблицы_toast, а её индексу назначается OID, равный oid_индекса_toast. Как и с declare index, заполнение индекса откладывается.

build indices

Заполнить индексы, объявленные ранее.

70.4. BKI Commands

create tablename tableoid [bootstrap] [shared_relation] [rowtype_oid oid] (name1 = type1 [FORCE NOT NULL | FORCE NULL ] [, name2 = type2 [FORCE NOT NULL | FORCE NULL ], ...])

Create a table named tablename, and having the OID tableoid, with the columns given in parentheses.

The following column types are supported directly by bootstrap.c: bool, bytea, char (1 byte), name, int2, int4, regproc, regclass, regtype, text, oid, tid, xid, cid, int2vector, oidvector, _int4 (array), _text (array), _oid (array), _char (array), _aclitem (array). Although it is possible to create tables containing columns of other types, this cannot be done until after pg_type has been created and filled with appropriate entries. (That effectively means that only these column types can be used in bootstrap catalogs, but non-bootstrap catalogs can contain any built-in type.)

When bootstrap is specified, the table will only be created on disk; nothing is entered into pg_class, pg_attribute, etc, for it. Thus the table will not be accessible by ordinary SQL operations until such entries are made the hard way (with insert commands). This option is used for creating pg_class etc themselves.

The table is created as shared if shared_relation is specified. The table's row type OID (pg_type OID) can optionally be specified via the rowtype_oid clause; if not specified, an OID is automatically generated for it. (The rowtype_oid clause is useless if bootstrap is specified, but it can be provided anyway for documentation.)

open tablename

Open the table named tablename for insertion of data. Any currently open table is closed.

close tablename

Close the open table. The name of the table must be given as a cross-check.

insert ( [oid_value] value1 value2 ... )

Insert a new row into the open table using value1, value2, etc., for its column values.

NULL values can be specified using the special key word _null_. Values that do not look like identifiers or digit strings must be double quoted.

declare [unique] index indexname indexoid on tablename using amname ( opclass1 name1 [, ...] )

Create an index named indexname, having OID indexoid, on the table named tablename, using the amname access method. The fields to index are called name1, name2 etc., and the operator classes to use are opclass1, opclass2 etc., respectively. The index file is created and appropriate catalog entries are made for it, but the index contents are not initialized by this command.

declare toast toasttableoid toastindexoid on tablename

Create a TOAST table for the table named tablename. The TOAST table is assigned OID toasttableoid and its index is assigned OID toastindexoid. As with declare index, filling of the index is postponed.

build indices

Fill in the indices that have previously been declared.

FAQ