示例#1
0
 public void TestInvaildAliasExprUsage(
     [IncludeDataSources(TestProvName.AllPostgreSQL)]
     string context)
 {
     using (var db = GetDataContext(context))
     {
         var query =
             from c in db.FromSql <int>($"select {1} {Sql.AliasExpr()}")
             select c;
         Assert.Throws <Npgsql.PostgresException>(() => query.ToArray());
     }
 }
示例#2
0
 public void TestUnnest(
     // `with ordinality` added to pgsql 9.4
     [IncludeDataSources(true, TestProvName.AllPostgreSQL95Plus)]
     string context)
 {
     using (var db = GetDataContext(context))
     {
         var query =
             from c in db.SelectQuery(() => Sql.Expr <int[]>("ARRAY[1,2]::int[]"))
             from s in db.FromSql <UnnestEnvelope <int> >($"unnest({c}) with ordinality {Sql.AliasExpr()} (value, index)")
             select s.Value;
         var result   = query.ToArray();
         var expected = new [] { 1, 2 };
         AreEqual(expected, result);
     }
 }
示例#3
0
 static Expression <Func <IDataContext, TValue[], IQueryable <UnnestEnvelope <TValue> > > > UnnestWithOrdinalityImpl <TValue>()
 => (db, member) => db.FromSql <UnnestEnvelope <TValue> >($"unnest({member}) with ordinality {Sql.AliasExpr()} (value, index)");
示例#4
0
 static IQueryable <UnnestEnvelope <TValue> > UnnestWithOrdinality <TValue>(IDataContext db, TValue[] member)
 => db.FromSql <UnnestEnvelope <TValue> >($"unnest({member}) with ordinality {Sql.AliasExpr()} (value, index)");
示例#5
0
 public void TestScalarSubquery(
     [IncludeDataSources(true, TestProvName.AllPostgreSQL93Plus)]
     string context)
 {
     using (var db = GetDataContext(context))
     {
         // ::text hint needed for pgsql < 10
         var query =
             from c in db.SelectQuery(() => "hello world")
             from s in db.FromSql <string>($"regexp_split_to_table({c}::text, E'\\\\s+') {Sql.AliasExpr()}")
             select s;
         var result   = query.ToArray();
         var expected = new[] { "hello", "world" };
         AreEqual(expected, result);
     }
 }
示例#6
0
 static Expression <Func <IDataContext, T[], IQueryable <Ordinality <T> > > > UnnestWithOrdinalityImpl <T>()
 {
     return((dc, array) => dc.FromSql <Ordinality <T> >($"UNNEST({array}) WITH ORDINALITY {Sql.AliasExpr()}(value, idx)"));
 }