所以我已經將我的代碼數據庫從h2更改爲postgresql,並且我注意到在h2中使用的Inner Join調用在調用它時沒有給出相同的結果PostgreSQL的。我已經完成了研究,經過測試,我發現左連接和其他連接完全起作用,只有內連接給了我不同的結果。因此,爲了使兩個輸出csv文件匹配,是否必須更改表的整個結構,或者在我忽略的postgresql中是否有類似的東西?INNER JOIN與h2數據庫和postgresql數據庫的差異
public void doAllWork(int type, Connection conn, Statement st) {
try {
if (type == 1) {
st.execute("DROP TABLE IF EXISTS COMBINEDDATA;"); //USING DISTINCT TO EXCLUDE DUPLICATE RECORDS
st.execute("ANALYZE");
st.execute("CREATE TABLE COMBINEDDATA AS \n"
+ "SELECT DISTINCT E.DATA1, E.DATA2, E.DATA3, E.DATA4, E.DATA5, E.DATA6, \n"
+ "E.DATA7, E.DATA8, E.DATA9, E.DATA10, E.DATA11, E.DATA12, E.DATA13, E.DATA14, E.DATA15, E.DATA16, E.DATA17, \n"
+ "E.DATA18, E.DATA19, E.DATA21, E.DATA26, E.DATA27, E.DATA28, E.DATA29, \n"
+ "E.DATA30, E.DATA31, E.DATA32, E.DATA34, E.DATA35, E.DATA36, E.DATA37, E.DATA38, \n"
+ " C.CHAIN20, C.CHAIN33, C.CHAIN22, \n "
+ "D.DAT2, D.DAT3, D.DAT4, D.DAT7, D.DAT11, D.DAT9, D.DAT5, \n "
+ "E.DATA39, E.DATA40, E.DATA41 FROM rawData AS E \n"
+ "RIGHT JOIN CHAINDATA AS C \n"
+ "ON E.DATA7 = c.CHAIN2\n"
+ "AND E.DATA11 = c.CHAIN4\n"
+ "AND E.DATA21 = c.CHAIN10\n"
+ "AND E.DATA22 = c.CHAIN11\n"
+ "RIGHT JOIN DATDATA AS D\n"
+ "ON E.DATA7 = D.DAT18\n"
+ "AND E.DATA11 = D.DAT21\n"
+ "AND UCASE(E.DATA6) = UCASE(D.DAT17)\n"
+ "AND UCASE(E.DATA10) = UCASE(D.DAT20)\n"
+ "AND UCASE(E.DATA5) = UCASE(D.DAT16)\n"
+ "AND UCASE(E.DATA9) = UCASE(D.DAT19)\n"
+ "AND E.DATA20 = D.DAT22");
} else if (type == 2) {
st.execute("DROP TABLE IF EXISTS COMBINEDDATA2;");
st.execute("ANALYZE");
st.execute("CREATE TABLE COMBINEDDATA2 AS \n"
+ "SELECT DISTINCT E.DATA1, E.DATA2, E.DATA3, E.DATA4, E.DATA5, E.DATA6, \n"
+ "E.DATA7, E.DATA8, E.DATA9, E.DATA10, E.DATA11, E.DATA12, E.DATA13, E.DATA14, E.DATA15, E.DATA16, E.DATA17, \n"
+ "E.DATA18, E.DATA19, E.DATA21, E.DATA26, E.DATA27, E.DATA28, E.DATA29, \n"
+ "E.DATA30, E.DATA31, E.DATA32, E.DATA34, E.DATA35, E.DATA36, E.DATA37, E.DATA38, \n"
+ " C.CHAIN20, C.CHAIN33, C.CHAIN22, \n "
+ "D.DAT2, D.DAT3, D.DAT4, D.DAT7, D.DAT11, D.DAT9, D.DAT5, \n "
+ "E.DATA39, E.DATA40, E.DATA41 FROM rawData AS E \n"
+ "LEFT JOIN CHAINDATA AS C \n"
+ "ON E.DATA7 = c.CHAIN2\n"
+ "AND E.DATA11 = c.CHAIN4\n"
+ "AND E.DATA21 = c.CHAIN10\n"
+ "AND E.DATA22 = c.CHAIN11\n"
+ "LEFT JOIN DATDATA AS D\n"
+ "ON E.DATA7 = D.DAT18\n"
+ "AND E.DATA11 = D.DAT21\n"
+ "AND UCASE(E.DATA6) = UCASE(D.DAT17)\n"
+ "AND UCASE(E.DATA10) = UCASE(D.DAT20)\n"
+ "AND UCASE(E.DATA5) = UCASE(D.DAT16)\n"
+ "AND UCASE(E.DATA9) = UCASE(D.DAT19)\n"
+ "AND E.DATA20 = D.DAT22");
}
System.out.println("here");
if (type == 1) {
String dir = System.getProperty("user.dir");
st.executeUpdate("CALL CSVWRITE('" + dir + "\\OnlyMatching.csv', 'SELECT * FROM COMBINEDDATA','charset=UTF-8');"); //,
} else if (type == 2) {
String dir = System.getProperty("user.dir");
st.executeUpdate("CALL CSVWRITE('" + dir + "\\AllNonMatching.csv', 'SELECT * FROM COMBINEDDATA2','charset=UTF-8');");
}
} catch (Exception ex) {
Logger.getLogger(RyderCombinerGUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
在上面的代碼中,用左手第二循環連接工程的H2和PostgreSQL相同,但內部聯接環路返回不同的東西。
提前感謝輸出。
噢好的,謝謝,進一步審查csv文件後,他們確實是在不同的順序相同。我對數據庫還很陌生,所以我對ORDER BY知之甚少,但我確信這確實是問題所在。 – JCole