malloydata / malloy-vscode-extension

The Malloy Visual Studio Code extension facilitates building Malloy data models, querying and transforming data, and creating simple visualizations and dashboards
http://www.malloydata.dev
MIT License
13 stars 12 forks source link

Postgresql Foreign Data Wrappers (FDW) are not recognized when using the SQL syntax #460

Closed asitemade4u closed 4 months ago

asitemade4u commented 5 months ago

Hi, So, in my Postgres database (pis) I quote foreign tables from a MySQL database using the FDW_MySQL extension. Works great. One of the tables is Tags in the schema zxt.

Malloy seamlessly recognizes the foreign tables when using its table syntax. For example:

source: tagbas is pis.table('zxt.Tags') extend {...}

That is GREAT.

However, when I try inserting a raw SQL block such as:

source: tagpoibas is pis.sql("""
    SELECT
        name AS nam,
        id,
        pid
    FROM zxt.Tags
    WHERE pid in (SELECT id FROM Tags WHERE kuq_plc is TRUE)
""")

Malloy complains and throws an error:

Invalid SQL, Error fetching schema for md5:/...

I have verified the query: it works fine in Datagrip.

asitemade4u commented 4 months ago

The issue was coming from the typing of the kuq_plc column in MariaDB: a bit. Obviously, after being transposed through FDW into Postgres, it was not well recognized by Malloy. Solved by re-typing kuq-plc into a smallint in MariaDB.