F # sqlite sqlprovider minBy maxBy using float

I have a sqlite table with a combination of integer and floating columns. I am trying to get the max and min values ​​of each column. For whole columns, the following code works, but I get an error when using the same code in float columns:

let numCats = query{for row in db do minBy row.NumCats}

For float columns, I use the following code, but it is slow.

let CatHight = query{for row in db do select row.CatHeight} |> Seq.toArray |> Array.max

I have 8 integer columns and 9 floating point columns, and the behavior was consistent across all columns, so I think this is a column type problem. But I'm new to F # and don't know anything, so I hope you can help me.

Thank you for taking the time to help, it was very much appreciated.

SQLProvider Version: 1.0.41

System.Data.SQLite.Core version: 1.0.104

Error: System.InvalidCastException occurred in FSharp.Core.dll

​​

float. 2.2 4.2. SQLProvider System.Data.SQLite.Core, minBy maxBy, cast. , .

:

System.Exception : "System.Exception" > FSharp.Core.dll : value(FSharp.Data.Sql.Runtime.QueryImplementation+SqlQueryable 1 [FSharp. > Data.Sql.Common.SqlEntity]). Min (row = → Convert (Convert (row.GetColumn( "X" )))) `

:

open FSharp.Data.Sql

[<Literal>]
let ConnectionString =
"Data Source=c:\MyDB.db;" +
"Version=3;foreign keys=true"

type Sql = SqlDataProvider<Common.DatabaseProviderTypes.SQLITE,
ConnectionString,
//ResolutionPath = resolutionPath,
CaseSensitivityChange = Common.CaseSensitivityChange.ORIGINAL>

let ctx = Sql.GetDataContext()
let Db = ctx.Main.Test

let x = query{for row in Db do minBy row.X}
printfn "x: %A" x

2/1/17

, SQLProvider. , , , , - . - , . .

let x = query {for row in db do
                sortBy row.Column
                take 1
                select row.Column } |> Seq.toArray |> Array.min
+4
2

, @s952163 SO f # . , .

let x = query {for row in db do
                sortBy row.Column
                take 1
                select row.Column } |> Seq.head
+2

int float ( , ). , . float ( ), int , , :

let x = query { for row in MYTABLE do
                minBy (int (float row.MYCOLUMN))}

, , float Mycolumn.

Update: Sqlite . query { ... } |> Seq.minBy, .

+1

Source: https://habr.com/ru/post/1668323/


All Articles