PostgreSQL Source Code git master
plpy_typeio.h
Go to the documentation of this file.
1/*
2 * src/pl/plpython/plpy_typeio.h
3 */
4
5#ifndef PLPY_TYPEIO_H
6#define PLPY_TYPEIO_H
7
8#include "access/htup.h"
9#include "fmgr.h"
10#include "plpython.h"
11#include "utils/typcache.h"
12
13struct PLyProcedure; /* avoid requiring plpy_procedure.h here */
14
15
16/*
17 * "Input" conversion from PostgreSQL Datum to a Python object.
18 *
19 * arg is the previously-set-up conversion data, val is the value to convert.
20 * val mustn't be NULL.
21 *
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.
25 */
26typedef struct PLyDatumToOb PLyDatumToOb; /* forward reference */
27
28typedef PyObject *(*PLyDatumToObFunc) (PLyDatumToOb *arg, Datum val);
29
30typedef struct PLyScalarToOb
31{
32 FmgrInfo typfunc; /* lookup info for type's output function */
34
35typedef struct PLyArrayToOb
36{
37 PLyDatumToOb *elm; /* conversion info for array's element type */
39
40typedef struct PLyTupleToOb
41{
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 */
51
52typedef struct PLyTransformToOb
53{
54 FmgrInfo typtransform; /* lookup info for from-SQL transform func */
56
58{
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 */
67 {
72 } u;
73};
74
75/*
76 * "Output" conversion from Python object to a PostgreSQL Datum.
77 *
78 * arg is the previously-set-up conversion data, val is the value to convert.
79 *
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.)
83 *
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.
86 */
87typedef struct PLyObToDatum PLyObToDatum; /* forward reference */
88
89typedef Datum (*PLyObToDatumFunc) (PLyObToDatum *arg, PyObject *val,
90 bool *isnull,
91 bool inarray);
92
93typedef struct PLyObToScalar
94{
95 FmgrInfo typfunc; /* lookup info for type's input function */
96 Oid typioparam; /* argument to pass to it */
98
99typedef struct PLyObToArray
100{
101 PLyObToDatum *elm; /* conversion info for array's element type */
102 Oid elmbasetype; /* element base type */
104
105typedef struct PLyObToTuple
106{
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 */
118
119typedef struct PLyObToDomain
120{
121 PLyObToDatum *base; /* conversion info for domain's base type */
122 void *domain_info; /* cache space for domain_check() */
124
125typedef struct PLyObToTransform
126{
127 FmgrInfo typtransform; /* lookup info for to-SQL transform function */
129
131{
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 */
140 {
146 } u;
147};
148
149
152 bool *isnull);
153
155 TupleDesc desc, bool include_generated);
156
158 Oid typeOid, int32 typmod,
159 struct PLyProcedure *proc);
161 Oid typeOid, int32 typmod,
162 struct PLyProcedure *proc);
163
165 struct PLyProcedure *proc);
167 struct PLyProcedure *proc);
168
170 struct PLyProcedure *proc);
171
172/* conversion from Python objects to C strings --- exported for transforms */
173extern PGDLLEXPORT char *PLyObject_AsString(PyObject *plrv);
174
175#endif /* PLPY_TYPEIO_H */
#define PGDLLEXPORT
Definition: c.h:1292
int16_t int16
Definition: c.h:483
int32_t int32
Definition: c.h:484
uint64_t uint64
Definition: c.h:489
long val
Definition: informix.c:689
void * arg
PyObject *(* PLyDatumToObFunc)(PLyDatumToOb *arg, Datum val)
Definition: plpy_typeio.h:28
PGDLLEXPORT PyObject * PLy_input_from_tuple(PLyDatumToOb *arg, HeapTuple tuple, TupleDesc desc, bool include_generated)
Definition: plpy_typeio.c:134
struct PLyObToTuple PLyObToTuple
struct PLyTransformToOb PLyTransformToOb
struct PLyObToDomain PLyObToDomain
struct PLyObToScalar PLyObToScalar
PGDLLEXPORT void PLy_output_setup_tuple(PLyObToDatum *arg, TupleDesc desc, struct PLyProcedure *proc)
Definition: plpy_typeio.c:215
PGDLLEXPORT char * PLyObject_AsString(PyObject *plrv)
Definition: plpy_typeio.c:1027
PGDLLEXPORT void PLy_output_setup_record(PLyObToDatum *arg, TupleDesc desc, struct PLyProcedure *proc)
Definition: plpy_typeio.c:261
struct PLyTupleToOb PLyTupleToOb
PGDLLEXPORT void PLy_output_setup_func(PLyObToDatum *arg, MemoryContext arg_mcxt, Oid typeOid, int32 typmod, struct PLyProcedure *proc)
Definition: plpy_typeio.c:296
PGDLLEXPORT void PLy_input_setup_func(PLyDatumToOb *arg, MemoryContext arg_mcxt, Oid typeOid, int32 typmod, struct PLyProcedure *proc)
Definition: plpy_typeio.c:418
struct PLyScalarToOb PLyScalarToOb
PGDLLEXPORT void PLy_input_setup_tuple(PLyDatumToOb *arg, TupleDesc desc, struct PLyProcedure *proc)
Definition: plpy_typeio.c:165
PGDLLEXPORT Datum PLy_output_convert(PLyObToDatum *arg, PyObject *val, bool *isnull)
Definition: plpy_typeio.c:120
struct PLyArrayToOb PLyArrayToOb
struct PLyObToArray PLyObToArray
struct PLyObToTransform PLyObToTransform
PGDLLEXPORT PyObject * PLy_input_convert(PLyDatumToOb *arg, Datum val)
Definition: plpy_typeio.c:81
Datum(* PLyObToDatumFunc)(PLyObToDatum *arg, PyObject *val, bool *isnull, bool inarray)
Definition: plpy_typeio.h:89
uintptr_t Datum
Definition: postgres.h:69
unsigned int Oid
Definition: postgres_ext.h:32
Definition: fmgr.h:57
PLyDatumToOb * elm
Definition: plpy_typeio.h:37
PLyArrayToOb array
Definition: plpy_typeio.h:69
PLyTransformToOb transform
Definition: plpy_typeio.h:71
PLyTupleToOb tuple
Definition: plpy_typeio.h:70
MemoryContext mcxt
Definition: plpy_typeio.h:65
PLyDatumToObFunc func
Definition: plpy_typeio.h:59
union PLyDatumToOb::@187 u
int32 typmod
Definition: plpy_typeio.h:61
int16 typlen
Definition: plpy_typeio.h:63
PLyScalarToOb scalar
Definition: plpy_typeio.h:68
PLyObToDatum * elm
Definition: plpy_typeio.h:101
PLyObToScalar scalar
Definition: plpy_typeio.h:141
MemoryContext mcxt
Definition: plpy_typeio.h:138
PLyObToDomain domain
Definition: plpy_typeio.h:144
PLyObToArray array
Definition: plpy_typeio.h:142
PLyObToTuple tuple
Definition: plpy_typeio.h:143
PLyObToDatumFunc func
Definition: plpy_typeio.h:132
PLyObToTransform transform
Definition: plpy_typeio.h:145
union PLyObToDatum::@188 u
PLyObToDatum * base
Definition: plpy_typeio.h:121
void * domain_info
Definition: plpy_typeio.h:122
FmgrInfo typfunc
Definition: plpy_typeio.h:95
FmgrInfo typtransform
Definition: plpy_typeio.h:127
TupleDesc recdesc
Definition: plpy_typeio.h:108
TypeCacheEntry * typentry
Definition: plpy_typeio.h:110
uint64 tupdescid
Definition: plpy_typeio.h:111
FmgrInfo recinfunc
Definition: plpy_typeio.h:116
PLyObToDatum * atts
Definition: plpy_typeio.h:113
FmgrInfo typfunc
Definition: plpy_typeio.h:32
FmgrInfo typtransform
Definition: plpy_typeio.h:54
PLyDatumToOb * atts
Definition: plpy_typeio.h:48
uint64 tupdescid
Definition: plpy_typeio.h:46
TupleDesc recdesc
Definition: plpy_typeio.h:43
TypeCacheEntry * typentry
Definition: plpy_typeio.h:45