﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
5421	"Add ""db_select"" hooks for database Fields"	Adrian Holovaty	nobody	"I'm proposing a ""db_select"" method on the database {{{Field}}} class. This would specify the raw SQL to use when listing the field in the {{{SELECT}}} clause of an SQL statement. This will allow for more useful SELECTs in the case of opaque data types such as PostGIS ""geometry"" fields, which are returned by default as an encoded series of bytes.

It could also allow certain fields, such as BLOBs, to *never* be returned in a SELECT statement. (I'm 50/50 on this particular idea.)

{{{
#!python
class Field:
    def db_select(self, table):
        # Default behavior is to select the column name.
        return '%s.%s' % (table, self.db_column)

class GeometryField(Field):
    def db_select(self, table):
        # For a PostGIS geometry field, select the textual version of the geometry.
        return 'AsText(%s.%s)' % (table, self.db_column)

class BlobField(Field):
    def db_select(self, table):
        # None means ""Don't ever include this field in a SELECT list.""
        return None
}}}"		closed	Database layer (models, ORM)	dev		fixed	feature_request		Design decision needed	0	0	0	0	0	0
