[Haskell-cafe] Typesafe multi-table PostgreSQL queries in Yesod with schema names?

Manuel Gómez targen at gmail.com
Wed Nov 20 05:11:45 UTC 2013


On Tue, Nov 19, 2013 at 11:20 PM, Erik de Castro Lopo
<mle+hs at mega-nerd.com> wrote:
> Manuel Gómez wrote:
>> *   Persistent: it’s perfectly integrated into Yesod, and together
>> with Esqueleto, it provides a nice, typesafe and fully expressive EDSL
>> — but, as far as I can tell, there is no support for specifying schema
>> names, which is essential for my use case.
>
> I'm not sure of what you mean here. DO you mean that you already have
> a database and schema and you now want to connect Persisent/Esqueleto
> to it without changing the existing schema?

Hi Erik,

Indeed, that’s more or less the situation I’m facing.  Perhaps the
overloading of the term “schema” is a problem here: what I
specifically meant with this point is the namespacing mechanism
present in (some implementations of) SQL databases: database object
names are bound within namespaces called schemas, and a name can be
qualified with the name of the schema, separated by a dot; hence a
table named `"with spaces"` in a schema/namespace called `"some
tables"` would be used qualified as `"some tables"."with spaces"`.

I have an existing schema (read: database) with many schemas (read:
namespaces) and I need to do joins between tables in them.  The names
have spaces and unusual bits of Unicode, and the dot that separates
the schema name from the object name mustn’t be quoted, so it’s not
simply a matter of specifying a complex name to Persistent, as
escaping and quoting wouldn’t be done correctly.  A workaround could
be to put everything in a single namespace and use prefixes in names,
but that causes other issues for me (other tools would break).

The other issue I have with Persistent+Esqueleto is that the database
I have to work with has some composite or otherwise non–serial-integer
primary keys, and I understand Persistent requires a serial primary
key.  I could probably work around this, though.


More information about the Haskell-Cafe mailing list