def create_table(context, data_dict):
 datastore_fields = [{'id': '_id', 'type': 'serial primary key'}, {'id': '_full_text', 'type': 'tsvector'}]
 extra_fields = []
 supplied_fields = data_dict.get('fields', [])
 check_fields(context, supplied_fields)
 field_ids = _pluck('id', supplied_fields)
 records = data_dict.get('records')
 for field in supplied_fields:
  if ('type' not in field):
   if ((not records) or (field['id'] not in records[0])):
    raise ValidationError({'fields': [u'"{0}" type not guessable'.format(field['id'])]})
   field['type'] = _guess_type(records[0][field['id']])
 unique_fields = set([f['id'] for f in supplied_fields])
 if (not (len(unique_fields) == len(supplied_fields))):
  raise ValidationError({'field': ['Duplicate column names are not supported']})
 if records:
  if (not isinstance(records[0], dict)):
   raise ValidationError({'records': ['The first row is not a json object']})
  supplied_field_ids = records[0].keys()
  for field_id in supplied_field_ids:
   if (field_id not in field_ids):
    extra_fields.append({'id': field_id, 'type': _guess_type(records[0][field_id])})
 fields = ((datastore_fields + supplied_fields) + extra_fields)
 sql_fields = u', '.join([u'"{0}" {1}'.format(f['id'], f['type']) for f in fields])
 sql_string = u'CREATE TABLE "{0}" ({1});'.format(data_dict['resource_id'], sql_fields)
 context['connection'].execute(sql_string.replace('%', '%%'))

def create_table ( context , data_dict ) : datastore_fields = [ { 'id' : '_id' , 'type' : 'serial primary key' } , { 'id' : '_full_text' , 'type' : 'tsvector' } ] extra_fields = [ ] supplied_fields = data_dict . get ( 'fields' , [ ] ) check_fields ( context , supplied_fields ) field_ids = _pluck ( 'id' , supplied_fields ) records = data_dict . get ( 'records' ) for field in supplied_fields : if ( 'type' not in field ) : if ( ( not records ) or ( field [ 'id' ] not in records [ 0 ] ) ) : raise ValidationError ( { 'fields' : [ u'"{0}" type not guessable' . format ( field [ 'id' ] ) ] } ) field [ 'type' ] = _guess_type ( records [ 0 ] [ field [ 'id' ] ] ) unique_fields = set ( [ f [ 'id' ] for f in supplied_fields ] ) if ( not ( len ( unique_fields ) == len ( supplied_fields ) ) ) : raise ValidationError ( { 'field' : [ 'Duplicate column names are not supported' ] } ) if records : if ( not isinstance ( records [ 0 ] , dict ) ) : raise ValidationError ( { 'records' : [ 'The first row is not a json object' ] } ) supplied_field_ids = records [ 0 ] . keys ( ) for field_id in supplied_field_ids : if ( field_id not in field_ids ) : extra_fields . append ( { 'id' : field_id , 'type' : _guess_type ( records [ 0 ] [ field_id ] ) } ) fields = ( ( datastore_fields + supplied_fields ) + extra_fields ) sql_fields = u', ' . join ( [ u'"{0}" {1}' . format ( f [ 'id' ] , f [ 'type' ] ) for f in fields ] ) sql_string = u'CREATE TABLE "{0}" ({1});' . format ( data_dict [ 'resource_id' ] , sql_fields ) context [ 'connection' ] . execute ( sql_string . replace ( '%' , '%%' ) )
create a table in the database .