{"record":{"id":"eceab1c27c1a01a3","repo":"pentaho/pentaho-kettle","slug":"no-fields-defined-to-load-to-database-pgbulkloader","errorCode":null,"errorMessage":"No fields defined to load to database","messagePattern":"No fields defined to load to database","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"plugins/postgresql-db-bulk-loader/impl/src/main/java/org/pentaho/di/trans/steps/pgbulkloader/PGBulkLoader.java","lineNumber":109,"sourceCode":"    //\n    // contents.append(\"SET DATESTYLE ISO;\"); // This is the default but we set it anyway...\n    // contents.append(Const.CR);\n\n    // Create a Postgres / Greenplum COPY string for use with a psql client\n    contents.append( \"COPY \" );\n    // Table name\n\n    contents.append( tableName );\n\n    // Names of columns\n\n    contents.append( \" ( \" );\n\n    String[] streamFields = meta.getFieldStream();\n    String[] tableFields = meta.getFieldTable();\n\n    if ( streamFields == null || streamFields.length == 0 ) {\n      throw new KettleException( \"No fields defined to load to database\" );\n    }\n\n    for ( int i = 0; i < streamFields.length; i++ ) {\n      if ( i != 0 ) {\n        contents.append( \", \" );\n      }\n      contents.append( dm.quoteField( tableFields[i] ) );\n    }\n\n    contents.append( \" ) \" );\n\n    // The \"FROM\" filename\n    contents.append( \" FROM STDIN\" ); // FIFO file\n\n    // The \"FORMAT\" clause\n    contents.append( \" WITH CSV DELIMITER AS '\" ).append( environmentSubstitute( meta.getDelimiter() ) )\n        .append( \"' QUOTE AS '\" ).append(\n      environmentSubstitute( meta.getEnclosure() ) ).append( \"'\" );","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/postgresql-db-bulk-loader/impl/src/main/java/org/pentaho/di/trans/steps/pgbulkloader/PGBulkLoader.java#L91-L127","documentation":"The PostgreSQL bulk loader step builds a COPY command from the mapped stream fields, and none were defined. getCopyCommand checks meta.getFieldStream() and aborts the transformation when the field mapping is empty, because a COPY without a column list is invalid for this step's generated SQL.","triggerScenarios":"Calling getCopyCommand (via copyCmd) when the step's field mapping table has no rows: meta.getFieldStream() returns null or an empty array, typically because the transformation was never fully configured or the field mappings were cleared.","commonSituations":"Importing a transformation XML or repository export where the field mapping did not persist; a 'Get Fields' was never clicked in the step dialog; upstream steps renamed/removed fields so the mapping grid saved empty; hand-editing the ktr and deleting the <fields> entries.","solutions":["Open the PGBulkLoader step dialog, go to the Fields tab, and click 'Get Fields' to populate the stream-to-table field mapping","Verify the transformation file/repository actually saved the field mappings (check the ktr XML for field entries under the step)","Ensure upstream steps produce fields before configuring the loader, then re-save the transformation","Repair the source transformation/step metadata so PGBulkLoaderMeta.getFieldStream() returns a non-empty array"],"exampleFix":"// before (empty mapping in step meta)\nString[] streamFields = meta.getFieldStream(); // null or length 0 -> KettleException\n// after (configure fields programmatically or via dialog)\nmeta.setFieldStream( new String[] { \"id\", \"name\" } );\nmeta.setFieldTable( new String[] { \"id\", \"name\" } );","handlingStrategy":"validation","validationCode":"String[] streamFields = meta.getFieldStream();\nif ( streamFields == null || streamFields.length == 0 ) {\n  throw new IllegalStateException( \"PGBulkLoader has no field mapping; open the Fields tab and use Get Fields\" );\n}","typeGuard":null,"tryCatchPattern":"try {\n  step.processRow();\n} catch ( KettleException e ) {\n  if ( e.getMessage().contains( \"No fields defined\" ) ) {\n    // reconfigure field mapping before retry\n  }\n}","preventionTips":["Always click 'Get Fields' in the Fields tab after selecting the target table","Version-control .ktr files and diff field mappings when importing transformations","Run a quick design-time validation that upstream steps produce fields before the loader"],"tags":["kettle","postgresql","configuration","bulk-loader"],"backgroundTag":"empty-required-field","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}