62.2. Команды BKI
createимя_таблицыoid_таблицы[bootstrap] [shared_relation] [without_oids] [rowtype_oidoid] (имя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, таблица создаётся как общая. Она будет содержать столбец OID, если отсутствует указаниеwithout_oids. Дополнительным предложениемrowtype_oidможет быть задан OID типа строки (OID записи вpg_type); если он не указан, OID генерируется автоматически. (Предложениеrowtype_oidбесполезно, если присутствует указаниеbootstrap, но его всё равно можно добавить для документирования.)-
openимя_таблицы Открыть таблицу
имя_таблицыдля добавления данных. Любая другая таблица, открытая в данный момент, закрывается.-
close[имя_таблицы] Закрыть открытую таблицу. Имя таблицы может задаваться для перепроверки, но это не требуется.
insert[OID =значение_oid](значение1значение2...)Вставить новую строку в открытую таблицу, установив
значение1,значение2и т. д. в качестве значений столбцов изначение_oidв качестве OID. Еслизначение_oidравно нулю (0) или это указание опущено, а таблица при этом содержит OID, строке назначается следующий свободный OID.Значения NULL могут задаваться специальным ключевым словом
_null_. Значения, содержащие пробелы, должны заключаться в двойные кавычки.-
declare[unique]indexимя_индексаoid_индексаonимя_таблицыusingимя_метода_доступа(класс_оп1имя1[, ...]) Создать индекс
имя_индексас OID, равнымoid_индекса, в таблицеимя_таблицы, с методом доступаимя_метода_доступа. Индекс строится по полямимя1,имя2и т. д., и для них используются соответственно классы операторовкласс_оп1,класс_оп2и т. д. Эта команда создаёт файл индекса и добавляет соответствующие записи в каталог, но не инициализирует содержимое индекса.-
declare toastoid_таблицы_toastoid_индекса_toastonимя_таблицы Создаёт таблицу TOAST для таблицы
имя_таблицы. Таблице TOAST назначается OID, равныйoid_таблицы_toast, а её индексу назначается OID, равныйoid_индекса_toast. Как и сdeclare index, заполнение индекса откладывается.build indicesЗаполнить индексы, объявленные ранее.
62.2. BKI Commands
-
createtablenametableoid[bootstrap] [shared_relation] [without_oids] [rowtype_oidoid] (name1=type1[FORCE NOT NULL | FORCE NULL ] [,name2=type2[FORCE NOT NULL | FORCE NULL ], ...]) Create a table named
tablename, and having the OIDtableoid, 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 afterpg_typehas been created and filled with appropriate entries. (That effectively means that only these column types can be used in bootstrapped tables, but non-bootstrap catalogs can contain any built-in type.)When
bootstrapis specified, the table will only be created on disk; nothing is entered intopg_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 (withinsertcommands). This option is used for creatingpg_classetc themselves.The table is created as shared if
shared_relationis specified. It will have OIDs unlesswithout_oidsis specified. The table's row type OID (pg_typeOID) can optionally be specified via therowtype_oidclause; if not specified, an OID is automatically generated for it. (Therowtype_oidclause is useless ifbootstrapis specified, but it can be provided anyway for documentation.)-
opentablename Open the table named
tablenamefor insertion of data. Any currently open table is closed.-
close[tablename] Close the open table. The name of the table can be given as a cross-check, but this is not required.
-
insert[OID =oid_value](value1value2...) Insert a new row into the open table using
value1,value2, etc., for its column values andoid_valuefor its OID. Ifoid_valueis zero (0) or the clause is omitted, and the table has OIDs, then the next available OID is assigned.NULL values can be specified using the special key word
_null_. Values containing spaces must be double quoted.-
declare[unique]indexindexnameindexoidontablenameusingamname(opclass1name1[, ...]) Create an index named
indexname, having OIDindexoid, on the table namedtablename, using theamnameaccess method. The fields to index are calledname1,name2etc., and the operator classes to use areopclass1,opclass2etc., 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 toasttoasttableoidtoastindexoidontablename Create a TOAST table for the table named
tablename. The TOAST table is assigned OIDtoasttableoidand its index is assigned OIDtoastindexoid. As withdeclare index, filling of the index is postponed.build indicesFill in the indices that have previously been declared.