public String generateSelectAllExistingFieldsSql ( Connection connection , String namespace ) throws SQLException { // select all columns from table // FIXME This is postgres-specific and needs to be made generic for non-postgres databases. PreparedStatement statement = connection . prepareStatement ( "SELECT column_name FROM information_schema.columns WHERE table_schema = ? AND table_name = ?" ) ; statement . setString ( 1 , namespace ) ; statement . setString ( 2 , name ) ; ResultSet result = statement . executeQuery ( ) ; // get result and add fields that are defined in this table List < Field > existingFields = new ArrayList <> ( ) ; while ( result . next ( ) ) { String columnName = result . getString ( 1 ) ; existingFields . add ( getFieldForName ( columnName ) ) ; } String tableName = String . join ( "." , namespace , name ) ; String fieldPrefix = tableName + "." ; return String . format ( "select %s from %s" , commaSeparatedNames ( existingFields , fieldPrefix , true ) , tableName ) ; }
Generate a select statement from the columns that actually exist in the database table . This method is intended to be used when exporting to a GTFS and eventually generates the select all with each individual field and applicable transformations listed out .