我正在尝试使用copy into <table> from file...
将csv文件加载到具有自动增量PK / Id列的monetdb表中。
有没有办法在加载数据时指定列?就像是
Copy into <tableName>( col2, col2,...) from file ...
?
对于(1),我发现的工作是删除自动增量pk / id列并稍后改变表。 对于(2)将文件加载到临时表中并稍后插入/更新实际表。虽然它变得很麻烦,更不用说插入/更新的开销而不是批量加载。
任何帮助/指针都会非常感激。
此致
答案 0 :(得分:1)
您是对的,the monetdb doc没有提及指定插入从CSV文件读取的数据的列的方法。 但是,为了实现这一点,您可以使用临时表,然后插入&#39; INSERT INTO&#39;使用选择子查询:
INSERT INTO <table>(<col1>, <col2>, ...) SELECT <col1>, <col2>, ... FROM tmp
&#34;插入&#34;来自子查询将等同于批量插入,并且应该非常快。
答案 1 :(得分:1)
解决方案主要取决于csv文件的格式,因此让我们看一个示例。
csv文件包含标题行,并用逗号分隔(注意/* in global css document: */
/* this makes it so that sort header arrow is always shown: */
.mat-sort-header-arrow.ng-trigger.ng-trigger-arrowPosition {
opacity: 1 !important;
color: blue;
}
/* Hide the default sort arrow display: */
.mat-sort-header-stem {
display: none !important;
}
.mat-sort-header-pointer-left, .mat-sort-header-pointer-right {
display: none !important;
}
.mat-sort-header-pointer-middle{
width: 0px !important;
height: 0px !important;
}
/* show two carets on top of each other when not sorted takes place: */
.mat-sort-header-arrow {
.mat-sort-header-indicator {
&::before {
content: "<>";
position: absolute;
opacity: 1 !important;
color: blue !important;
font-size: 1.2em;
font-weight: bold;
transform: translate(-10%, 20%) rotate(90deg) !important;
}
}
}
/* show ascending caret when sorted ascending:*/
[aria-sort="ascending"] {
.mat-sort-header-arrow {
.mat-sort-header-indicator {
&::before {
content: "<";
position: absolute;
color: blue !important;
opacity: 1 !important;
font-size: 1.2em;
font-weight: bold;
transform: translate(0,0) rotate(90deg) !important;
}
}
}
}
/* show descending caret when sorted descending: */
[aria-sort="descending"] {
.mat-sort-header-arrow {
.mat-sort-header-indicator {
&::before {
content: ">";
position: absolute;
color: blue !important;
opacity: 1 !important;
font-size: 1.2em;
font-weight: bold;
transform: translate(0,-10%) rotate(90deg) !important;
}
}
}
}
默认字段分隔符为 monetdb
)。
#cat /path/to/file.csv
val1,val2,val3
asd,2,23
dsa,3,24
'|'
sql>CREATE TABLE example (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, val1 VARCHAR(30),val2 INT, val3 INT);
sql>COPY OFFSET 2 INTO example (val1, val2, val3) FROM '/path/to/file.csv' (val1, val2, val3) DELIMITERS ',';
确保标头未复制到表中。OFFSET 2
部分是必需的,因为我们不想复制example (val1, val2, val3) FROM '/path/to/file.csv' (val1, val2, val3)
列的值。id
是必需的,因为默认字段分隔符为'|'。有关更多详细信息,请参见https://www.monetdb.org/Documentation/ServerAdministration/LoadingBulkData