Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple group by query with postgresql causes doubling up of double quotes when using double quoted declared fields #795

Open
kgday opened this issue Jul 6, 2023 · 3 comments

Comments

@kgday
Copy link

kgday commented Jul 6, 2023

In PostGreSq with a table where the fields are declared double quotedl, I have the following query:

                let! costs =
                    query {
                        for pol in ctx.Public.PurchaseOrderLine do
                            where (pol.JobId.Value = prodOrderID)
                            groupBy (pol.JobId, pol.ChargeAccount) into g
                            select 
                                {
                                    JobID = g.Key |> fst |> Option.defaultValue 0L
                                    ChargeAccount = g.Key |> snd
                                    TotalCost = g.Sum(fun o -> o.TotalCost)
                                }
                    }
                    |> Seq.executeQueryAsync   

The following sql is emitted:

SELECT "pol"."JobID" as ""pol"."JobID"", "pol"."ChargeAccount" as ""pol"."ChargeAccount"", SUM("pol"."TotalCost") as "pol.SUM_TotalCost" FROM "public"."PurchaseOrderLine" as "pol" WHERE (("pol"."JobID" = @param1)) GROUP BY "pol"."JobID", "pol"."ChargeAccount">, Parameters<@param1=12482>

Note the as parts have been double quoted twice. This causes postgresql to return an error:

zero-length delimited identifier at or near """"

In fairness, groupby is discouraged in the docs.

The work arround obviously for me at present is to create a view or do the grouping in the client. But I would have thought this was a simple enough group by.

@kgday kgday changed the title simply group by query with postgresql causes doubling up of double quotes Simple group by query with postgresql causes doubling up of double quotes Jul 6, 2023
@kgday kgday changed the title Simple group by query with postgresql causes doubling up of double quotes Simple group by query with postgresql causes doubling up of double quotes when using double quoted declared fields Jul 6, 2023
@Thorium
Copy link
Member

Thorium commented Jul 6, 2023

This does work in MSSQL so probably wouldn't be too hard to fix in Postgres

Thorium added a commit that referenced this issue Oct 21, 2023
@Thorium
Copy link
Member

Thorium commented Oct 21, 2023

I don't have Postgres so I can't test if it works in the latest version after this tiny fix. I'd expect it might do the query properly but may struggle to bring the results back to executing code.

@Thorium
Copy link
Member

Thorium commented Oct 21, 2023

I think the proper fix should be implementing selection of quote-characters like FireBird here: https://github.com/fsprojects/SQLProvider/pull/453/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants