Comments (7)
I don't think it's going to be possible to embed COPY FROM STDIN inside an SQL script file like that - although I'll investigate a little. On the other hand I don't think it would offer any performance advantages over simple inserting with multiple values, the latter would probably even be safer:
INSERT INTO "City" ("Id", "DepartementId", "Insee", "Line5", "Name", "Population", "PostalCode", "PostalName") VALUES
(1, '01', '001', 'Abergement-Clémenciat', '825 01400', 'L ABERGEMENT CLEMENCIAT'),
(2, '01', '002', 'Abergement-de-Varey', '204 01640', 'L ABERGEMENT DE VAREY');
Using COPY programmatically is also a possibility as you say, with either BeginTextImport (or BeginBinaryImport, depending on whether on what you have on the client side). But that takes things out of the migration script.
from efcore.pg.
I found the error, when i execute the database update, i have a fixture file which execute after the database creation. This c# file find the sql files to insert the datas. Only now i have 2 new files which contains an instruction COPY instead of INSERT.
example
--
-- PostgreSQL database dump
--
SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET search_path = public, pg_catalog;
--
-- Data for Name: City; Type: TABLE DATA; Schema: public; Owner: jerome
--
COPY "City" ("Id", "DepartementId", "Insee", "Line5", "Name", "Population", "PostalCode", "PostalName") FROM stdin;
1 01 001 Abergement-Clémenciat 825 01400 L ABERGEMENT CLEMENCIAT
2 01 002 Abergement-de-Varey 204 01640 L ABERGEMENT DE VAREY
3 01 004 Ambérieu-en-Bugey 13144 01500 AMBERIEU EN BUGEY
4 01 005 Ambérieux-en-Dombes 1469 01330 AMBERIEUX EN DOMBES
5 01 006 Ambléon 120 01300 AMBLEON
This file is generated with the command
pg_dump -a -d MediagralEF -n public -t '"City"' > City.sql
I use the sql method of MigrationBuilder to execute this file
protected override void Up(MigrationBuilder migrationBuilder)
{
string sql = "";
try
{
foreach(string file in Directory.GetFiles(@"Migrations/PostgreSql/Fixtures/Base").OrderBy(f => f)) {
sql = File.ReadAllText(file);
migrationBuilder.Sql(sql, true);
}
sql = File.ReadAllText(@"Migrations/PostgreSql/CorrErreurTables.sql");
migrationBuilder.Sql(sql, true);
}
catch (System.Exception)
{
System.Console.WriteLine("Erreur dans le fichier : " + sql);
throw;
}
}
Only the files which contains the COPY instruction failed. Maybe i should use the ngpsql connector directly with the BeginTextImport instead of migrationBuilder. I already use BeginTextImport for an another migration phase.
from efcore.pg.
After investigation, the small files with COPY are ok, but i have a huge file (282 mo) which is the origin of exception.
from efcore.pg.
OK, in that case there's probably a bug somewhere in Npgsql, I'll try to investigate.
from efcore.pg.
Argh! no the small files throw the exception also.
I will use the insert instruction in place.
from efcore.pg.
it's ok, no error with the inserts.
sorry for this issue, false alert.
Thanks.
from efcore.pg.
On pg_dump
, the flag --column-inserts
will switch the COPY
to INSERT
from efcore.pg.
Related Issues (20)
- Error while Querying scalar with context.Database function HOT 4
- ENUMs don't use fully qualified namespaces in ModelSnapshot which causes collisions HOT 2
- Plans for Entity Framework 9 (EF9) support? HOT 2
- Question: Correct way to rotate database credentials when using a datasource HOT 5
- Additional DateOnly related translation
- Missing checks for predicate when simplifying primitive collections
- Translation error when storing NodaTime `(Instant, TimeZoneId)` and filtering on local date time values HOT 1
- Add support for foreign key match types (FULL, PARTIAL, SIMPLE) HOT 1
- JsonPolymorphic support HOT 1
- Unable to create a 'DbContext' of type 'ApplicationDbContext' While trying to create migrations npgsql HOT 5
- Unable to configure separate migrations assembly when setting up Aspire HOT 2
- Group by entity with xmin/xid concurrency token throws
- Arrays of type with value converter fail in query generation HOT 4
- Is it possible to connect to multiple databases in a multitenant scenario? HOT 4
- "bad protocol version" error when connecting to PostgreSQL HOT 3
- Look into IS DISTINCT FROM as an alternative to nullability semantics compensation HOT 2
- Missing ordering on ORDINALITY column when projecting out primitive collections with composed LINQ operators HOT 7
- Translate primitive collections with composed LINQ operators via PG array constructor
- [Bug] Connection already open on Database.Migrate() HOT 2
- Migrations references actual enum types which break them HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from efcore.pg.