Import
元データはタブ区切り。
NpgsqlConnection conn = new NpgsqlConnection(conStr);
conn.Open();
using (var writer = conn.BeginTextImport("COPY Accounts (account_id, record_date, prc_amount) FROM STDIN"))
{
writer.Write(File.ReadAllText(@"table_import.txt", Encoding.GetEncoding(932)));
}
conn.Close();
Export
NULLは空文字に変更。行末はLFとなる。
NpgsqlConnection conn = new NpgsqlConnection(conStr);
conn.Open();
using (var reader = conn.BeginTextExport("COPY (select account_id, record_date, prc_amount from Accounts order by account_id) TO STDOUT NULL ''"))
{
File.WriteAllText(@"table_export.txt", reader.ReadToEnd(), Encoding.GetEncoding(932));
}
conn.Close();
参考情報
- https://www.npgsql.org/doc/copy.html
- https://www.postgresql.jp/document/11/html/ecpg-sql-connect.html
- https://www.postgresql.jp/document/11/html/sql-copy.html
- https://www.postgresql.jp/document/11/html/datatype.html
- https://www.postgresql.jp/document/11/html/functions-datetime.html
- https://www.postgresql.jp/document/11/html/functions-formatting.html
- https://www.postgresql.jp/document/11/html/functions-string.html
- https://www.postgresql.jp/document/11/html/sql-createsequence.html