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

Possible to make EXCEPT keyword work? #208

Open
oguimbal opened this issue Mar 29, 2022 Discussed in #197 · 0 comments
Open

Possible to make EXCEPT keyword work? #208

oguimbal opened this issue Mar 29, 2022 Discussed in #197 · 0 comments
Labels
enhancement New feature or request needs-parser-work

Comments

@oguimbal
Copy link
Owner

Discussed in #197

Originally posted by jasonfilippou March 17, 2022
Hi,

I have the following (abstract) query that I am trying to pass to pg-mem:

(
     select DISTINCT tab1.staff_username                  as staff_id,
                     tab3.rcm_organization_code           as org_code
     from table1 tab1
              JOIN table2 tab2 ON predicate1
              JOIN table3 tab3 ON predicate2

     UNION

     select DISTINCT tab4.staff_username                  as staff_id,
                     tab5.rcm_organization_code           as org_code
     from table4 tab4
              JOIN table5 tab5 ON predicate3
              JOIN table6 tab6 ON predicate4
     WHERE NOT EXISTS(SELECT 1
                      from some_other_table
                      where some_other_predicate)
)

EXCEPT

select v.staff_id, v.organization_code
from another_table

Unfortunately, it seems as if pg-mem does not yet support EXCEPT:

Error: Error: 💔 Your query failed to parse.
This is most likely due to a SQL syntax error. However, you might also have hit a bug, or an unimplemented feature of pg-mem.
.
.
.
💀 Syntax error at line 22 col 17:

                  EXCEPT
                  ^
Unexpected kw_except token: "except". Instead, I was expecting to see one of the following:

    - A "kw_union" token
.
.
.

I DO know how to register functions in pg-mem and have done so for some:

pgMem.public.registerFunction({
    name: 'TRIM',
    args: [DataType.text],
    returns: DataType.text,
    implementation: str => return str != null ? str.trim() : null
});

pgMem.getSchema().registerFunction({
    name: 'now',
    returns: DataType.timestamp,
    implementation: () => moment().toISOString()
});

But for EXCEPT, I am not sure if this can be done! We are, after all, talking about functions that manipulate record sets, not strings or dates, for which registerFunction() works well. It is possible for me to implement EXCEPT in memory, but for technical reasons, we need to limit the amount of in-memory (Javascript) manipulations and instead offload everything we can to the SQL.

Any ideas? Is this possible in pg-mem? MINUS does NOT appear to be a supported pg-mem or even psql operator.

@oguimbal oguimbal added enhancement New feature or request needs-parser-work labels May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs-parser-work
Projects
None yet
Development

No branches or pull requests

1 participant