def create_table_sql(tablename, fields, geom_type, geom_srid):
    """
    Create a SQL statement for creating a table. Based on a geoJSON
    representation. For simplicity all fields are declared VARCHAR 255
    (not good, I know, patches welcome)
    """
    cols = []
    for field in fields:
        cols.append("%s VARCHAR(255)" % field)

    statement = """CREATE TABLE %s (
                id SERIAL,
                %s,
                geom GEOMETRY(%s, %s),
                PRIMARY KEY (id)
                )
                """ %(tablename, ",\n".join(cols), geom_type, geom_srid)
    return statement