34.12. Большие объекты
ECPG не поддерживает большие объекты напрямую, но приложение на базе ECPG может работать с большими объектами, используя предназначенные для этого функции, получив необходимый объект PGconn
в результате вызова ECPGget_PGconn()
. (Однако использовать функцию ECPGget_PGconn()
и напрямую воздействовать на объекты PGconn
следует очень осторожно; в идеале стоит исключить при этом другие обращения к базе данных через ECPG.)
Подробнее функция ECPGget_PGconn()
описана в Разделе 34.11. Интерфейс функций для работы с большими объектами рассмотрен в Главе 33.
Функции для работы с большими объектами должны вызываться в блоке транзакций, поэтому если режим автофиксации отключён, необходимо явно выдавать команды BEGIN
.
В Примере 34.2 приведён пример программы, показывающий, как создать, записать и прочитать большой объект в приложении ECPG.
Пример 34.2. Программа на базе ECPG, работающая с большими объектами
#include <stdio.h> #include <stdlib.h> #include <libpq-fe.h> #include <libpq/libpq-fs.h> EXEC SQL WHENEVER SQLERROR STOP; int main(void) { PGconn *conn; Oid loid; int fd; char buf[256]; int buflen = 256; char buf2[256]; int rc; memset(buf, 1, buflen); EXEC SQL CONNECT TO testdb AS con1; EXEC SQL SELECT pg_catalog.set_config('search_path', '', false); EXEC SQL COMMIT; conn = ECPGget_PGconn("con1"); printf("conn = %p\n", conn); /* create */ loid = lo_create(conn, 0); if (loid < 0) printf("lo_create() failed: %s", PQerrorMessage(conn)); printf("loid = %d\n", loid); /* write test */ fd = lo_open(conn, loid, INV_READ|INV_WRITE); if (fd < 0) printf("lo_open() failed: %s", PQerrorMessage(conn)); printf("fd = %d\n", fd); rc = lo_write(conn, fd, buf, buflen); if (rc < 0) printf("lo_write() failed\n"); rc = lo_close(conn, fd); if (rc < 0) printf("lo_close() failed: %s", PQerrorMessage(conn)); /* read test */ fd = lo_open(conn, loid, INV_READ); if (fd < 0) printf("lo_open() failed: %s", PQerrorMessage(conn)); printf("fd = %d\n", fd); rc = lo_read(conn, fd, buf2, buflen); if (rc < 0) printf("lo_read() failed\n"); rc = lo_close(conn, fd); if (rc < 0) printf("lo_close() failed: %s", PQerrorMessage(conn)); /* check */ rc = memcmp(buf, buf2, buflen); printf("memcmp() = %d\n", rc); /* cleanup */ rc = lo_unlink(conn, loid); if (rc < 0) printf("lo_unlink() failed: %s", PQerrorMessage(conn)); EXEC SQL COMMIT; EXEC SQL DISCONNECT ALL; return 0; }
54.26. pg_index
#
The catalog pg_index
contains part of the information about indexes. The rest is mostly in pg_class
.
Table 54.26. pg_index
Columns
Column Type Description |
---|
The OID of the |
The OID of the |
The total number of columns in the index (duplicates |
The number of key columns in the index, not counting any included columns, which are merely stored and do not participate in the index semantics |
If true, this is a unique index |
This value is only used for unique indexes. If false, this unique index will consider null values distinct (so the index can contain multiple null values in a column, the default Postgres Pro behavior). If it is true, it will consider null values to be equal (so the index can only contain one null value in a column). |
If true, this index represents the primary key of the table ( |
If true, this index supports an exclusion constraint |
If true, the uniqueness check is enforced immediately on insertion (irrelevant if |
If true, the table was last clustered on this index |
If true, the index is currently valid for queries. False means the index is possibly incomplete: it must still be modified by |
If true, queries must not use the index until the |
If true, the index is currently ready for inserts. False means the index must be ignored by |
If false, the index is in process of being dropped, and should be ignored for all purposes (including HOT-safety decisions) |
If true this index has been chosen as “replica identity” using |
This is an array of |
For each column in the index key ( |
For each column in the index key ( |
This is an array of |
Expression trees (in |
Expression tree (in |