SQLProvider icon indicating copy to clipboard operation
SQLProvider copied to clipboard

postgresql materialized views missing

Open mjsottile opened this issue 9 years ago • 11 comments

I am having trouble using the current version of the SQLProvider from github with a PostgreSQL database that uses materialized views. Tables and normal views show up fine, but the materialized views do not show up at all. Is this a known issue?

mjsottile avatar May 22 '15 05:05 mjsottile

I don't even know what a materialized view is! @janno-p ?

If you look at the source however you can see the query against INFORMATION_SCHEMA that we currently use to retrieve the tables / views.

pezipink avatar May 22 '15 07:05 pezipink

This is true across all of the providers currently, shouldn't be that hard to add thou.

-----Original Message----- From: "Ross McKinlay" [email protected] Sent: ‎22/‎05/‎2015 08:09 To: "fsprojects/SQLProvider" [email protected] Subject: Re: [SQLProvider] postgresql materialized views missing (#136)

I don't even know what a materialized view is! @janno-p ? If you look at the source however you can see the query against INFORMATION_SCHEMA that we currently use to retrieve the tables / views. — Reply to this email directly or view it on GitHub.

colinbull avatar May 22 '15 08:05 colinbull

marked this as up for grabs then, might be a nice one for someone to pickup?

pezipink avatar May 22 '15 13:05 pezipink

It seems this is still up for grabs... there are two advantage to materialized views, as they are stored on the disk, 1. it's extremely fast to query, just like a table. I benchmarked a simple three column group by query, it's 500ms (View) vs 0.1ms (Materialized View). And 2., since sqlprovider doesn't (yet) do groupvalby, any groupby or other missing query functionality can be implemented server side, and then just queried from a materialized view. Just bumping it in the hope someone tackles this.

s952163 avatar Mar 28 '17 04:03 s952163

With Oracle someone has fixed similar issue: #345

Thorium avatar Apr 03 '17 10:04 Thorium

Searching a bit more this, it's not so easy task. Postgres materialized views don't belong to standard SQL information_schema.

After Postgres version 9.3 the views are listed in pg_matviews so they could be fetched from there. I tried to combine those with tables:

SELECT  table_schema,
        table_name,
        table_type
FROM  information_schema.tables
WHERE  table_schema = '%s'
UNION ALL
SELECT  schemaname as table_schema,
        matviewname as table_name,
        'M_VIEW' as table_type
FROM  pg_matviews
WHERE  schemaname = '%s'

But the next problem is that then the column-lookups (and relationship-lookups) for those fails as they are neither in information_schema.columns. So GetColumns should be rewritten also.

Thorium avatar Apr 03 '17 12:04 Thorium

Thanks for looking into this! I appreciate the difficulty of this.

s952163 avatar Apr 06 '17 09:04 s952163

There is any update on this issue? I'm having this problem:

 error FS0039: The type 'my_schemaSchema' does not define the field, constructor or member 'MyMaterializedView'

OnofreTZK avatar Apr 11 '24 22:04 OnofreTZK

I'm not actively using Postgres, but I will accept PRs.

Thorium avatar Apr 12 '24 06:04 Thorium

As a workaround, could you create a view / sp that uses the materialised view and query that with SQLProvider?

Thorium avatar Apr 12 '24 07:04 Thorium

FYI, the two queries you will need to implement materialized views were recently implemented in latest version of SqlHydra here: https://github.com/JordanMarr/SqlHydra/blob/main/src/SqlHydra.Cli/Npgsql/NpgsqlSchemaProvider.fs

Feel free to reuse the queries for SQLProvider.

JordanMarr avatar Apr 21 '24 19:04 JordanMarr