Обсуждение: CREATE TYPE function examples
I'm looking for some examples of how the functions for CREATE TYPE should be. There are none in the documentation, so I was hoping to find someone here that could help me.For example, the documentation has this example: CREATE TYPE box (INTERNALLENGTH = 8, INPUT = my_procedure_1, OUTPUT = my_procedure_2); What would the functions my_procedure_1 and my_procedure_2 look like? Thanks, -Roberto -- +----| http://fslc.usu.edu USU Free Software & GNU/Linux Club |------+ Roberto Mello - Computer Science, USU - http://www.brasileiro.net http://www.sdl.usu.edu - Space Dynamics Lab, Developer YES!! eh, NO!!! oh, well MAYBE!!!!!!!!
Roberto Mello writes: > I'm looking for some examples of how the functions for CREATE TYPE > should be. There are none in the documentation, so I was hoping to find > someone here that could help me. http://www.ca.postgresql.org/users-lounge/docs/7.1/postgres/xtypes.html This seems to be outdated regarding the fmgr update, though. (Hint, hint...) -- Peter Eisentraut peter_e@gmx.net http://funkturm.homeip.net/~peter
On Tue, Jul 10, 2001 at 06:43:59PM +0200, Peter Eisentraut wrote: > > http://www.ca.postgresql.org/users-lounge/docs/7.1/postgres/xtypes.html Oh. So you have to write a function in C to use CREATE TYPE? > This seems to be outdated regarding the fmgr update, though. (Hint, > hint...) How so? Would you please elaborate? I'm note familiar with the update. -Roberto -- +----| http://fslc.usu.edu USU Free Software & GNU/Linux Club |------+ Roberto Mello - Computer Science, USU - http://www.brasileiro.net http://www.sdl.usu.edu - Space Dynamics Lab, Developer Politically correct? I'm not even ANATOMICALLY correct!
Roberto Mello <rmello@cc.usu.edu> writes:
> What would the functions my_procedure_1 and my_procedure_2 look like?
src/backend/utils/adt/ is full of examples of datatype I/O procedures.
Pick an existing type that does something vaguely like your type
(at the very least pick one that uses the same kind of representation:
pass-by-value, fixed-length pass-by-reference, or variable-length),
and use its code as a model.
The only thing you need to do differently in dynamically loaded C code
than is done in the main sources is to declare version-1 calling
convention functions with PG_FUNCTION_INFO_V1(). This is assumed for
builtin functions as of 7.1, but the default for dynamically loaded
functions is to assume old-style calling conventions.
regards, tom lane