private SqlNode getNthExpr(SqlNode query, int ordinal, int sourceCount) {
		if (query instanceof SqlInsert) {
			SqlInsert insert = (SqlInsert) query;
			if (insert.getTargetColumnList() != null) {
				return insert.getTargetColumnList().get(ordinal);
			} else {
				return getNthExpr(
					insert.getSource(),
					ordinal,
					sourceCount);
			}
		} else if (query instanceof SqlUpdate) {
			SqlUpdate update = (SqlUpdate) query;
			if (update.getTargetColumnList() != null) {
				return update.getTargetColumnList().get(ordinal);
			} else if (update.getSourceExpressionList() != null) {
				return update.getSourceExpressionList().get(ordinal);
			} else {
				return getNthExpr(
					update.getSourceSelect(),
					ordinal,
					sourceCount);
			}
		} else if (query instanceof SqlSelect) {
			SqlSelect select = (SqlSelect) query;
			if (select.getSelectList().size() == sourceCount) {
				return select.getSelectList().get(ordinal);
			} else {
				return query; // give up
			}
		} else {
			return query; // give up
		}
	}
private SqlNode getNthExpr ( SqlNode query , int ordinal , int sourceCount ) { if ( query instanceof SqlInsert ) { SqlInsert insert = ( SqlInsert ) query ; if ( insert . getTargetColumnList ( ) != null ) { return insert . getTargetColumnList ( ) . get ( ordinal ) ; } else { return getNthExpr ( insert . getSource ( ) , ordinal , sourceCount ) ; } } else if ( query instanceof SqlUpdate ) { SqlUpdate update = ( SqlUpdate ) query ; if ( update . getTargetColumnList ( ) != null ) { return update . getTargetColumnList ( ) . get ( ordinal ) ; } else if ( update . getSourceExpressionList ( ) != null ) { return update . getSourceExpressionList ( ) . get ( ordinal ) ; } else { return getNthExpr ( update . getSourceSelect ( ) , ordinal , sourceCount ) ; } } else if ( query instanceof SqlSelect ) { SqlSelect select = ( SqlSelect ) query ; if ( select . getSelectList ( ) . size ( ) == sourceCount ) { return select . getSelectList ( ) . get ( ordinal ) ; } else { return query ; } } else { return query ; } }
Locates the n'th expression in an INSERT or UPDATE query.

@param query       Query
@param ordinal     Ordinal of expression
@param sourceCount Number of expressions
@return Ordinal'th expression, never null