@@ -509,6 +509,53 @@ void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesRow x, QuerySql.GetPos
509509 }
510510 """
511511 } ,
512+ [ KnownTestType . PostgresJsonCopyFrom ] = new TestImpl
513+ {
514+ Impl = $$ """
515+ [Test]
516+ [TestCase(100, "{\"song\": \"Pinball Wizard\", \"album\": \"Tommy\", \"artist\": \"The Who\"}")]
517+ [TestCase(10, null)]
518+ public async Task TestPostgresJsonCopyFrom(int batchSize, string cJson)
519+ {
520+ JsonElement? cParsedJson = null;
521+ if (cJson != null)
522+ cParsedJson = JsonDocument.Parse(cJson).RootElement;
523+
524+ var batchArgs = Enumerable.Range(0, batchSize)
525+ .Select(_ => new QuerySql.InsertPostgresSpecialTypesBatchArgs
526+ {
527+ CJson = cParsedJson,
528+ CJsonb = cParsedJson
529+ })
530+ .ToList();
531+ await QuerySql.InsertPostgresSpecialTypesBatch(batchArgs);
532+
533+ var expected = new QuerySql.GetPostgresSpecialTypesCntRow
534+ {
535+ Cnt = batchSize,
536+ CJson = cParsedJson,
537+ CJsonb = cParsedJson
538+ };
539+ var actual = await QuerySql.GetPostgresSpecialTypesCnt();
540+ AssertSingularEquals(expected, actual{{ Consts . UnknownRecordValuePlaceholder }} );
541+
542+ void AssertSingularEquals(QuerySql.GetPostgresSpecialTypesCntRow x, QuerySql.GetPostgresSpecialTypesCntRow y)
543+ {
544+ var options = new JsonSerializerOptions
545+ {
546+ WriteIndented = false
547+ };
548+ Assert.That(y.Cnt, Is.EqualTo(x.Cnt));
549+ Assert.That(y.CJson.HasValue, Is.EqualTo(x.CJson.HasValue));
550+ if (y.CJson.HasValue)
551+ Assert.That(JsonSerializer.Serialize(y.CJson.Value, options), Is.EqualTo(JsonSerializer.Serialize(x.CJson.Value, options)));
552+ Assert.That(y.CJsonb.HasValue, Is.EqualTo(x.CJsonb.HasValue));
553+ if (y.CJsonb.HasValue)
554+ Assert.That(JsonSerializer.Serialize(y.CJsonb.Value, options), Is.EqualTo(JsonSerializer.Serialize(x.CJsonb.Value, options)));
555+ }
556+ }
557+ """
558+ } ,
512559 [ KnownTestType . PostgresInvalidJson ] = new TestImpl
513560 {
514561 Impl = $$ """
0 commit comments