Custom type's modifiers
От | Marthin Laubscher |
---|---|
Тема | Custom type's modifiers |
Дата | |
Msg-id | 9964489E-E1FF-4E16-89D5-6804DD7C2A4B@lobeshare.co.za обсуждение исходный текст |
Ответы |
Re: Custom type's modifiers
|
Список | pgsql-hackers |
Hi, I’m defining a custom type “MyType” with additional functions and an custom aggregate in a C-coded extension. From a PostgreSQLperspective it is a base type that piggybacks on the bytea type, i.e. LIKE = BYTEA. But now I need to (re)define MyType to support type modifiers (e.g. MyType(1,14,18)) and I got that done using CREATE TYPE’sTYPMOD_IN and TYPMOD_OUT parameters resulting in the correct packed value getting stored in pg_attribute when I definea column of that type. But when I pass a MyType value to a function defined in my C extension how would I access the type modifier value for theargument which could have been drawn from the catalog or the result of a cast. E.g. if I: SELECT MyFunc(‘xDEADBEEF’::MyType(1,14,18)); In the C function MyFunc calls I get a pointer to the data using PG_GETARG_BYTEA_P(0) macro and its length using the VARSIZEmacro but I also need the given type modifiers (1, 14 and 18 in the example) before I can process the data correctly.Clearly I'd have to unpack the component values myself from the 16-bit atttypemod value into which the TYPMOD_OUTfunction has packed it, but where would I get access to that value? My type is written in C to be as fast as possiblehaving to go do some SPI-level lookup or involved logic would slow it right down again. My searches to date only yielded results referring to the value stored for a table in pg_attribute with the possibility ofthere being a value in HeapTupleHeader obtained by using the PG_GETARG_HEAPTUPLEHEADER(0) macro but that assumes the parameteris a tuple, not the individual value it actually is. I struggle to imagine that the type modifier value isn't beingmaintained by whatever casts are applied and not getting passed through to the extension already, but where to findit? Can someone please point me in the right direction here, the name of the structure containing the raw type modifier value,the name of the value in that structure, the name of a macro that accesses it, even if it’s just what keywords to searchfor in the documentation and/or archives? Even if it’s just a pointer to the code where e.g. the numeric type (whichhas type modifiers) is implemented so I can see how that code does it. Anything, I’m getting desperate. Perhaps notmany before me needed to do this so it's not often mentioned, but sure it is in there somewhere, how else would type likenumeric and even varchar actually work (given that the VARSIZE of a varlena gives its actual size, not the maximum asgiven when the column or value was created)? Thank you in advance, Marthin Laubscher
В списке pgsql-hackers по дате отправления: