Multi-valued user-defined types
Multi-valued user-defined types
От:
Stephen Frost <sfrost@snowman.net>
Дата:
Greetings, * Tom Lane (tgl@sss.pgh.pa.us) wrote: > Does anyone have examples of real user-defined types that would need two > fields? If not it may not be worth spending time on. Guess I'm jumping in a little late on this, but when reading the threads linked to from the TODO items on user-defined types and typmod parameters I immediately thought of PostGIS and the current 'geometry' type. I've discussed this some with the PostGIS folks and I think they have a definite real-world use-case for multi-valued user-defined types. They achieve this at the moment by using a table in the public sceham to keep the extra information regarding the column since they can't put it in pg_attribute (which is certainly where it belongs). The information for each attribute is: Number of dimensions Spatial Referencing System (identified by the SRID) Type (ie: Point, Polygon, etc) This is pretty standard among GIS databases (indeed, the table they keep this information in is actually defined by the OpenGIS specification and includes these attributes). Ideally, this would be a view rather than a table and the actual information would be stored in pg_attribute (attypmod). It would also mean that the input/output functions could ensure only valid information is put into the columns instead of having to rely on constraints put on the table. The options for how to handle this, in order of what I believe the preference is: POINT(dims, srid) - eg: POINT(2,4269) geometry(dims, srid, type) - eg: geometry(2,4269,'POINT') POINT_2D(srid) - eg: POINT_2D(4269) geometry - eg: geometry (constraints, side-table) SRID is pretty uniformly defined to be an int4 itself, though the PostGIS folks seemed to think it could be cut to 30-bits (2 bits for dimension is enough for them) if necessary. I'd really like to see custom types able to support mutli-values (and to have numeric changed to whatever the new mechanism is). As for how this might be handled in the backend, my thinking was to have a function for parsing the parameters which is passed in a cstring/varchar/etc and then returns a complex type of some kind. My original thought was to return a bytea but an anyarray may also work. Another thought which was mentioned was to add more 'attypmod' columns, ala pg_statistic's stanumbersN columns. I did read through the threads linked from the TODO item but wasn't very clear from those where things stand now. My intention (and understanding based on the threads) is that the goal would be to have this in 8.3. I'm interested in helping to realize this goal as I've become very annoyed at having to deal with this side-table or use functions to add geometry columns. :) Thanks, Stephen ----- Forwarded message from Markus Schaber ----- Date: Wed, 06 Sep 2006 11:48:36 +0200 From: Markus Schaber To: PostGIS Users Discussion Organization: Logical Tracking and Tracing International AG, Switzerland User-Agent: Thunderbird 1.5.0.5 (X11/20060812) Reply-To: PostGIS Users Discussion X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,FORGED_RCVD_HELO autolearn=ham version=3.1.3 Subject: Re: [postgis-users] What's the Purpose of the Geometry_Columns Table? Hi, Strk, strk@refractions.net wrote: >> Agreement with Markus. >> >> CREATE TABLE thetable ( thegeom GEOMETRY(4326,2,'POLYGON') ); > > Also: > > CREATE TABLE thetable ( thegeom ST_POLYGON2D(4326) ) > > (this won't need *multi_valued* typmod) That's right. Due to the small number of geometry and dimension combinations, we could possibly implement them using domains over GEOMETRY, but that's not feasible for the SRIDs. I don't know yet how DOMAINs affect the type names transmitted in the client protocol, so it's possible that the jdbc / j2ee / python geotypes have to be updated, but that might be the case for multi-valued typemods, too. And, finally, shielding the applications via abstraction over such changes is the whole point of those projects. Happy Committing, Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org _______________________________________________ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users ----- End forwarded message -----
Re: Multi-valued user-defined types
От:
Martijn van Oosterhout <kleptog@svana.org>
Дата:
On Wed, Sep 06, 2006 at 12:50:20PM -0400, Stephen Frost wrote:
> The information for each attribute is:
>
> Number of dimensions
> Spatial Referencing System (identified by the SRID)
> Type (ie: Point, Polygon, etc)
> POINT(dims, srid) - eg: POINT(2,4269)
> geometry(dims, srid, type) - eg: geometry(2,4269,'POINT')
> POINT_2D(srid) - eg: POINT_2D(4269)
> geometry - eg: geometry (constraints, side-table)
>
> SRID is pretty uniformly defined to be an int4 itself, though the
> PostGIS folks seemed to think it could be cut to 30-bits (2 bits for
> dimension is enough for them) if necessary.
User-defined typmod would be cool. As long as you don't want to rely on
the typmod to decode the Datums, it's really just a grammer change. I
proposed a while ago that users be allowed to provide a function that
converts the extra params into an int32 which is the actual typmod.
So the point type would be declared as having a typmod function
"point_typmod". So you could have point_typmod(int4) and
point_typmod(int4,int4) to handle both cases. I don't think we should
be tied to only integers as parameters, I'd like to be able to do:
CREATE TABLE ... ( string_field text('latin1'), ...
Whether that's a good way to do that particular feature, I don't know,
but if it's possible I think that would indicate our system is flexable
enough.
Someone posted a patch to the grammer which seemed to work, I don't
think in and of itself it is very difficult. As long as you don't want
to have the typmod to avoid storing data in the datum (which the
raw(64) example is) it should be fairly straightforward...
Hope this helps,
--
Martijn van Oosterhout http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.