public static String tableSchemaFromMetaData(
    		ResultSetMetaData rsMetaData) throws SQLException {
    	
        final StringBuilder createQuery = new StringBuilder();

        for (int i = 1; i <= rsMetaData.getColumnCount(); i++) {

            if (i != 1) {
                createQuery.append(",");
            }

            if ((rsMetaData.getColumnType(i) == Types.VARCHAR
                    || rsMetaData.getColumnType(i) == Types.CHAR)
                    && !rsMetaData.getColumnTypeName(i).equalsIgnoreCase("TEXT") // PostgreSQL TEXT identifies as Types.VARCHAR, but shouldn't have size
                    && !rsMetaData.getColumnTypeName(i).equalsIgnoreCase("BPCHAR") // Same problem as above, but for Types.CHAR
                    ) {
                createQuery.append(String.format("%s %s(%s)",
                        rsMetaData.getColumnLabel(i),
                        rsMetaData.getColumnTypeName(i),
                        rsMetaData.getColumnDisplaySize(i)));
            } else {
                createQuery.append(String.format("%s %s",
                        rsMetaData.getColumnLabel(i),
                        rsMetaData.getColumnTypeName(i)));
            }
        }

        return createQuery.toString();
    }