Commit Graph

495 Commits

Author SHA1 Message Date
Shane
3cc8099037
Expose unsafeUnnullify and unsafeUnnullifyTable (#343) 2024-09-18 12:48:29 +01:00
Teo Camarasu
b86e397e70
Support ghc-9.10 (#340) 2024-08-23 10:17:45 +01:00
Teo Camarasu
9580b6ffb3
Disallow NULL characters in Hedgehog generated text values (#339)
These are not permitted by postgresql and they lead to a runtime error.
2024-08-07 13:54:55 +00:00
Teo Camarasu
d9a6244417
Fix fromRational bug (#338)
Postgresql and Haskell differ in how they print numbers at the limits of
a double's precision. When these numbers have whole digits, we have less
precision to give to the decimal part, so we need to be less accurate
than 1e15.
2024-08-07 13:52:39 +00:00
remeike
b384871b24
Fix regex match operator (#336) 2024-08-05 13:07:59 +00:00
Shane
e214b75565
Remove Table Expr b constraint from materialize (#334)
Not only is this not necessary, it can actually act as a barrier to optimisation. The reason I added it was because it seemed like a cheap way to stop someone writing `query' <- materialize query id` — if you return the materialized query from `materialized`, it won't work. Really we would need some sort of `runST` type trick here to do this properly, but that would be too invasive a change.
2024-07-30 17:08:25 +00:00
Shane
149ec23c6f
Add aggregate{Just,Left,Right,This,That,Those,Here,There}Table{,1} aggregators (#333)
These provide another way to do aggregation of `MaybeTable`, `EitherTable` and `TheseTable`s than the existing `aggregate{Maybe,Either,These}Table`.
2024-07-15 11:54:22 +01:00
Teo Camarasu
dbda2da7bc
docs: fix haddock link (#332)
Previously this linked to Prelude.fromIntegral, but we mean Rel8.Num.fromIntegral
2024-07-02 15:41:09 +00:00
Shane
6b0721b4ca
Expose listOf and nonEmptyOf (#330)
It was an oversight that these were ever not exported.
2024-07-01 11:56:48 +00:00
Teo Camarasu
d8ca92fe85
Fix code block format (#329)
Without the indentation, this doesn't parse properly
2024-06-20 17:28:57 +01:00
Teo Camarasu
21b1733486
docs: remove empty 'where' clause (#327)
This hanging where statement seems like a typo or the ghost of a proper where long gone
2024-05-29 15:56:49 +01:00
abigailalice
6ec03667c4
Fix some markup in haddocks (#318)
Fixes #315.
2024-04-03 15:57:50 +01:00
Ollie Charles
4c184471d1
Release 1.5.0.0 (#298) 2024-03-19 14:48:26 +00:00
abigailalice
f1caa45fbf
Fix some unescaped markup in haddocks (#316)
* Fix some unescaped markup in haddocks

This addresses #315

* Expand documentation on unsafeDefault

This copies the documentation in the cookbook to the haddocks,
addressing #233.

* Update docs/concepts/insert.rst

Co-authored-by: Ollie Charles <ollie@ocharles.org.uk>

---------

Co-authored-by: Ollie Charles <ollie@ocharles.org.uk>
2024-03-19 10:09:31 +00:00
Ollie Charles
f7d3fa65be
Support Hedgehog 1.5 (#317) 2024-03-18 15:22:03 +00:00
George Karachalias
77fb0a3262
Fix typos in the documentation of Rel8.Expr.Eq.(/=.) (#312) 2024-03-05 13:00:12 +00:00
Ollie Charles
5959c8d964
Build with GHC 9.8.1 (#299) 2024-02-21 12:40:30 +00:00
Shane
95df13f6e5
Make sure fromRational can handle repeating fractions (#309) 2024-02-20 18:21:28 +00:00
Shane
ca615eeddf
Update Rel8 to work with Opaleye's #586 (#305) 2024-02-09 15:11:03 +00:00
Rob Taintor
a20ce005b4
Fix docs for min function (#306)
probably a copy paste error from "max"
2024-02-09 14:41:33 +00:00
Shane
2cbf663f59
Switch to WITH _ AS MATERIALIZED (_) for materialize (#284) 2024-01-09 01:31:36 +00:00
Shane
b5789a692e
Add ability to use custom aggregation functions with aggregateFunction (#283) 2024-01-09 01:28:04 +00:00
Shane
91e7a1bfab
Make Composite's text parser handle text containing double quotes (#304) 2024-01-09 01:19:51 +00:00
Shane
2d9b6abc74
Add ordered set aggregation functions (#282) 2024-01-08 21:28:04 +00:00
Shane
dee4f8a3aa
Upgrade flake (#303) 2024-01-08 17:50:35 +00:00
Chris Manning
6df1bd2a9d
Export Decoder to allow user-defined DBType instances (#297) 2023-12-05 12:35:06 +00:00
Shane
4a772725f4
Wrap rebind in dummy offset 0 (#289)
Somewhere between PostgreSQL 11 and PostgreSQL 15, PostgreSQL's optimiser gained the ability to see "through" subqueries, and it seems to choose to do this even when we don't really want it to.

E.g., it started transforming the following:

```haskell
SELECT
  x * y + x * y
FROM (
  SELECT
    a + b + c AS x
    d + e + f AS y
  FROM
    foo
) _
```

into:

```haskell
SELECT
  (a + b + c) * (d + e + f) + (a + b + c) * (d + e + f)
FROM
  foo
```

before evaluating.

You can see how more complicated expressions nested several levels deep could get expanded into crazy big expressions. This seems to be what PostgreSQL actually does on Rel8 code that uses `rebind`. Compared to older versions of PostgreSQL, this increases the planning time and execution time dramatically.

Given that Rel8's `rebind` is intended to function as a "let binding", and the user needs to go out of their way to choose to use it (they could just use `pure` if they wanted the fully expanded expression), we want a way to force PostgreSQL to evaluate the `a + b + c` and the `d + e + f` first before worrying about trying to simplify `x * y + x * y`. Adding `OFFSET 0` to the inner query seems to achieve that.

```haskell
SELECT
  x * y + x * y
FROM (
  SELECT
    a + b + c AS x
    d + e + f AS y
  FROM
    foo
  OFFSET
    0
) _
```
2023-10-29 19:40:31 +00:00
Shane
a744f058cf
Relax type of distinctAggregate (#287)
The `Sql DBEq a` constraint on the return type of the aggregator was wrong. It also isn't quite right to have a `EqTable i` constraint on the input type of the `Aggregator`, because technically what we want is a `Sql DBEq` constraint on whichever column(s) within `i` are used by aggregation functions, but we don't know which columns were used at this point. We could give `distinctAggregate` a type like `Sql DBEq i => Aggregator (Expr i) a` and make people run it through `lmap` manually, but that makes it impractical to use with `ListTable` without exposing more machinery. So we just drop the equality constraint for now.
2023-10-20 14:22:23 +01:00
Shane
bfb437fea1
Move some ListTable operations to Rel8.Array to avoid name clashes (#286) 2023-10-20 12:17:36 +01:00
Shane
9fb416607d
Add index and index1 for indexing arrays (ListTable and NonEmptyTable) (#285) 2023-10-19 18:40:07 +01:00
Shane
d0ba116149
Change window functions to operate on tables rather than columns (#281) 2023-10-07 12:11:29 +00:00
Ashwin Mathi
fbce52a287
Fix typo in dbtype.rst (#273) 2023-10-07 07:49:43 +00:00
Shane
7636a86fb3
Add DBType instance for Fixed (#280)
This resolves issue #218.
2023-10-06 16:15:35 +01:00
Shane
7eec1f85ee
Add loopDistinct (#277) 2023-10-02 18:33:31 +00:00
Shane
d058b6467b
Upgrade flake inputs (#278) 2023-09-29 11:23:22 +00:00
Shane
0ebb70f95f
Add array concenation aggregators (#270) 2023-09-27 10:41:27 +00:00
Shane
10eab21d3a
Support nested catListTable (by represented nested arrays as text) (#242)
This is one possible "fix" to #168. With this we can `catListTable` arbitrarily deep trees of `ListTable`s.

It comes at a relatively high cost, however.

Currently we represent nested arrays with anonymous records. This works reasonably well, except that we can't extract the field from the anonymous record when we need it (PostgreSQL [theoretically](https://www.postgresql.org/docs/13/release-13.html#id-1.11.6.16.5.6) suports `.f1` syntax since PG13 but it only works in very limited situations). But it does mean we can decode the results using Hasql's binary decoders, and ordering works how we expect ('array[row(array[9])] < array[row(array[10])]'.

What this PR does is instead represent nested arrays as text. To be able to decode this, we need each 'DBType' to supply a text parser in addition to a binary decoder. It also means that ordering is no longer intuitive, because `array[array[9]::text] > array[array[10]::text]`. However, it does mean we can nest `catListTable`s to our heart's content and it will always just work.
2023-09-27 11:39:04 +01:00
Shane
72a76aaf9a
Postgres' pi() function is lowercase (#275) 2023-09-21 14:47:32 +00:00
Shane
8a468f51c9
Length of empty array should return 0, not NULL (#269) 2023-08-16 02:07:24 +00:00
Shane
9e7a44757c
Add length{,1} functions for getting the length of {List,NonEmpty}Tables (#268) 2023-08-15 18:09:13 +00:00
Shane
0e24745497
Allow partial indexes as upsert conflict targets (#264) 2023-08-01 15:00:05 +01:00
Shane
c06bd5f2f1
Expand use of QualifiedName to types, composites, enums (#263)
Types in PostgreSQL can also be qualified with a schema. However, it's not sufficient to just change the type of `TypeInformation`'s `typeName` to `QualifiedName`, because a type isn't *just* a name. Postgres types can also be parameterised by modifiers (e.g., `numeric(7, 2)`) and array types of arbitrary depth (e.g., `int4[][]`).

To accomodate this, a new type is introduced, `TypeName`. Like `QualifiedName`, it has an `IsString` instance, so the common case (`schema` set to `Nothing`, no modifiers, scalar type) will continue working as before.
2023-07-23 17:12:02 +01:00
Shane
7ec674d2a8
Make binaryOperator take a QualifiedName instead of a String (#262) 2023-07-15 16:24:36 +01:00
Shane
cdf0c761d3
Export materialize (#260)
The main reason I wasn't happy with this before is that there was nothing stopping you from writing `materialize query pure`. This returned query would produce invalid SQL if you actually tried to use it, because it would attempt to reference a common table expression outside the scope of the `WITH` statement.

The "solution" here is just to throw a `rebind` around the result such that `materialize` incurs an extra `Table Expr b` constraint, which means that you can't return `Query (Query a)` because `Query a` can't satisfy a `Table Expr` constraint.
2023-07-15 11:25:04 +00:00
Shane
9f372dc649
Support selecting from table-returning functions with queryFunction (#241)
This fixes #71.
2023-07-11 14:32:24 +01:00
Shane
bf63d70ff3
Unify function and nullaryFunction (#258)
This does away with the weird variadic arguments thing we had going on with `function`.

Functions with no arguments are now written as:

```haskell
now :: Expr UTCTime
now = function "now" ()
```

Functions with multiple arguments are now written as:

```haskell
quot :: Sql DBIntegral a => Expr a -> Expr a -> Expr a
quot n d = function "div" (n, d)
```

Single-argument functions are written exactly as before.
2023-07-11 14:05:02 +01:00
Shane
c778ac1763
Introduce QualifiedName (fixes #228) (#257)
This adds a new type `QualifiedName` for named PostgreSQL objects (tables, views, functions and sequences) that can optionally be qualified by a schema. Previously only `TableSchema` could be qualified in this way.

`QualifiedName` has an `IsString` instance so the common case (where the schema is `Nothing`) doesn't have to care about schemas (if `OverloadedStrings` is enabled).

This also refactors `TableSchema` to use `QualifiedName` for its `name` field and drops its `schema` field.

Thanks to @elldritch for the bug report and the inspiration.
2023-07-11 12:06:36 +00:00
Ollie Charles
8cec776fa6
Set up scriv and add pending changelog entries (#255) 2023-07-11 11:49:53 +00:00
Ollie Charles
6554cfc841
Switch to Opaleye 0.9.7.0 (#259)
We actually require this now, so this updates the lower bound, and builds from Hackage rather than a `source-repository-package`.
2023-07-08 22:58:24 +01:00
Ollie Charles
5d07aa549d
Hide Rel8.materialise (#256) 2023-07-07 18:22:36 +00:00