Encontré la respuesta después de preguntar esto. Básicamente hay un archivo llamado catalog/pg_type.h, junto con libpq-fe.h y postgres.h. Debe incluir después de incluir libpq-fe.h y postgres.h, luego puede acceder a las definiciones como TEXTOID
, BOOLOID
, INT4OID
etc.
#include <stdio.h>
#include <postgres.h>
#include <libpq-fe.h>
#include <catalog/pg_type.h>
// ... snip ...
if (PQgetisnull(result, row, col)) {
// value is NULL, nothing more to do
} else {
char * value = PQgetvalue(result, row, col);
int length = PQgetlength(result, row, col);
switch (PQftype(result, col)) {
case INT2OID:
case INT4OID:
case INT8OID:
// process value as an integer
break;
default:
// just default to a text representation
}
}
Debe mirar todos los OID en pg_type.h para tener una lista extensa, o simplemente probar lo que obtiene haciendo SELECT 't'::boolean
básico. escriba consultas, etc. y construya el interruptor solo cuando necesite un nuevo tipo compatible.