2 * src/pl/plpython/plpy_typeio.h
8 #include "access/htup.h"
11 #include "utils/typcache.h"
13 struct PLyProcedure
; /* avoid requiring plpy_procedure.h here */
17 * "Input" conversion from PostgreSQL Datum to a Python object.
19 * arg is the previously-set-up conversion data, val is the value to convert.
20 * val mustn't be NULL.
22 * Note: the conversion data structs should be regarded as private to
23 * plpy_typeio.c. We declare them here only so that other modules can
24 * define structs containing them.
26 typedef struct PLyDatumToOb PLyDatumToOb
; /* forward reference */
28 typedef PyObject
*(*PLyDatumToObFunc
) (PLyDatumToOb
*arg
, Datum val
);
30 typedef struct PLyScalarToOb
32 FmgrInfo typfunc
; /* lookup info for type's output function */
35 typedef struct PLyArrayToOb
37 PLyDatumToOb
*elm
; /* conversion info for array's element type */
40 typedef struct PLyTupleToOb
42 /* If we're dealing with a RECORD type, actual descriptor is here: */
44 /* If we're dealing with a named composite type, these fields are set: */
45 TypeCacheEntry
*typentry
; /* typcache entry for type */
46 uint64 tupdescid
; /* last tupdesc identifier seen in typcache */
47 /* These fields are NULL/0 if not yet set: */
48 PLyDatumToOb
*atts
; /* array of per-column conversion info */
49 int natts
; /* length of array */
52 typedef struct PLyTransformToOb
54 FmgrInfo typtransform
; /* lookup info for from-SQL transform func */
59 PLyDatumToObFunc func
; /* conversion control function */
60 Oid typoid
; /* OID of the source type */
61 int32 typmod
; /* typmod of the source type */
62 bool typbyval
; /* its physical representation details */
65 MemoryContext mcxt
; /* context this info is stored in */
66 union /* conversion-type-specific data */
71 PLyTransformToOb transform
;
76 * "Output" conversion from Python object to a PostgreSQL Datum.
78 * arg is the previously-set-up conversion data, val is the value to convert.
80 * *isnull is set to true if val is Py_None, false otherwise.
81 * (The conversion function *must* be called even for Py_None,
82 * so that domain constraints can be checked.)
84 * inarray is true if the converted value was in an array (Python list).
85 * It is used to give a better error message in some cases.
87 typedef struct PLyObToDatum PLyObToDatum
; /* forward reference */
89 typedef Datum (*PLyObToDatumFunc
) (PLyObToDatum
*arg
, PyObject
*val
,
93 typedef struct PLyObToScalar
95 FmgrInfo typfunc
; /* lookup info for type's input function */
96 Oid typioparam
; /* argument to pass to it */
99 typedef struct PLyObToArray
101 PLyObToDatum
*elm
; /* conversion info for array's element type */
102 Oid elmbasetype
; /* element base type */
105 typedef struct PLyObToTuple
107 /* If we're dealing with a RECORD type, actual descriptor is here: */
109 /* If we're dealing with a named composite type, these fields are set: */
110 TypeCacheEntry
*typentry
; /* typcache entry for type */
111 uint64 tupdescid
; /* last tupdesc identifier seen in typcache */
112 /* These fields are NULL/0 if not yet set: */
113 PLyObToDatum
*atts
; /* array of per-column conversion info */
114 int natts
; /* length of array */
115 /* We might need to convert using record_in(); if so, cache info here */
116 FmgrInfo recinfunc
; /* lookup info for record_in */
119 typedef struct PLyObToDomain
121 PLyObToDatum
*base
; /* conversion info for domain's base type */
122 void *domain_info
; /* cache space for domain_check() */
125 typedef struct PLyObToTransform
127 FmgrInfo typtransform
; /* lookup info for to-SQL transform function */
132 PLyObToDatumFunc func
; /* conversion control function */
133 Oid typoid
; /* OID of the target type */
134 int32 typmod
; /* typmod of the target type */
135 bool typbyval
; /* its physical representation details */
138 MemoryContext mcxt
; /* context this info is stored in */
139 union /* conversion-type-specific data */
141 PLyObToScalar scalar
;
144 PLyObToDomain domain
;
145 PLyObToTransform transform
;
150 extern PGDLLEXPORT PyObject
*PLy_input_convert(PLyDatumToOb
*arg
, Datum val
);
151 extern PGDLLEXPORT Datum
PLy_output_convert(PLyObToDatum
*arg
, PyObject
*val
,
154 extern PGDLLEXPORT PyObject
*PLy_input_from_tuple(PLyDatumToOb
*arg
, HeapTuple tuple
,
155 TupleDesc desc
, bool include_generated
);
157 extern PGDLLEXPORT
void PLy_input_setup_func(PLyDatumToOb
*arg
, MemoryContext arg_mcxt
,
158 Oid typeOid
, int32 typmod
,
159 struct PLyProcedure
*proc
);
160 extern PGDLLEXPORT
void PLy_output_setup_func(PLyObToDatum
*arg
, MemoryContext arg_mcxt
,
161 Oid typeOid
, int32 typmod
,
162 struct PLyProcedure
*proc
);
164 extern PGDLLEXPORT
void PLy_input_setup_tuple(PLyDatumToOb
*arg
, TupleDesc desc
,
165 struct PLyProcedure
*proc
);
166 extern PGDLLEXPORT
void PLy_output_setup_tuple(PLyObToDatum
*arg
, TupleDesc desc
,
167 struct PLyProcedure
*proc
);
169 extern PGDLLEXPORT
void PLy_output_setup_record(PLyObToDatum
*arg
, TupleDesc desc
,
170 struct PLyProcedure
*proc
);
172 /* conversion from Python objects to C strings --- exported for transforms */
173 extern PGDLLEXPORT
char *PLyObject_AsString(PyObject
*plrv
);
175 #endif /* PLPY_TYPEIO_H */