您好 JMP 社區,
我在這裡搜尋您的幫助,因為我在其他帖子中沒有找到適合自己的足夠的解決方案。它是將資料表的內容寫入資料庫的表中。
為此我寫了這個小函數:
myInsertInto = function({dt, dbConnection, destinationName},
cols = dt << GetColumnNames(String);
rows = dt << Select All Rows << GetSelectedRows;
show(cols, rows);
//prepare sql head
sqlHead = "Insert Into " || destinationName || " (";
for each({col, index}, cols,
if(index == Length(cols),
sqlHead = sqlHead || col ||")",
sqlHead = sqlHead || col ||",";
)
);
//prepare sql body
sqlBody = "Values\!n";
ForEach({row, index}, rows,
sqlBody = sqlBody || "(";
show(row);
values = dt[row,0];
show(values);
for each({val, index}, values,
if(type(val) == "String",
if(IsMissing(val),
tmpVal = "null",
tmpVal = "'"||val||"'"
)
,
if(IsMissing(val),
tmpVal = "null",
tmpVal = char(val)
)
);
if(index == Length(values),
sqlBody = sqlBody || tmpVal ||")",
sqlBody = sqlBody || tmpVal ||",";
)
);
if(index == Length(rows),
sqlBody = sqlBody || ";",
sqlBody = sqlBody || ",\!n"
);
);
sqlQurey = sqlHead || "\!n" || sqlBody;
New SQL Query(
Version( 130 ),
Connection( myDbHandle ),
QueryName( "messwert.test_struktur_dennis" ),
Custom SQL(
Substitute(sqlQurey,"\!n", "", "\!t", "")
)
)<< run;
return(sqlQurey)
);該函數做了它應該做的事情,但有一些我不知道如何解決的限制。例如,我們使用 postgresql 資料庫,其中表格具有時間戳記、日期或其他格式化列。我不知道如何將其包含到我的函數中,因為 JMP 將所有這些格式化類型視為數字。
另一個問題是處理資料重複。使用我的函數,資料表的內容將被盲目地插入到我們的資料庫中。這可能會導致重複,因為我不知道已經存在什麼。我在另一篇文章中發現了這個功能:
dt << 儲存資料庫( dbc,
“dbo.假”,
代替
);
不幸的是,這將取代我無法使用的整張桌子。
因此我想向社區尋求幫助。有誰知道可以解決這些問題的插件或腳本解決方案?