supabase: Valid query containing `UNIQUE NULLS NOT DISTINCT` is not validated
Bug report
- I confirm this is a bug with Supabase, not with my own application.
- I confirm I have searched the Docs, GitHub Discussions, and Discord.
Describe the bug
In Postgres 15, the NULLS NOT DISTINCT syntax was introduced. However, queries including this syntax fail in Studio - both on CLI and app.supabase.com
To Reproduce
- Create a new database, either via app.supabase.com or with supabase CLI
- Go to the SQL editor
- Run a command that includes the
NULLS NOT DISTINCTsyntax
It will fail withCREATE TABLE new_style ( id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, val1 TEXT NOT NULL, val2 TEXT NULL, CONSTRAINT uq_val1_val2_new UNIQUE NULLS NOT DISTINCT (val1, val2) );Failed to validate sql query: syntax error at or near "NULLS" - Or create a table and try to add a constraint
CREATE TABLE new_style ( id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, val1 TEXT NOT NULL, val2 TEXT NULL ); ALTER TABLE new_style ADD CONSTRAINT uq_val1_val2_new UNIQUE NULLS NOT DISTINCT (val1, val2); - Connect to the database with a client like Postico, and the command will work ok.
Expected behavior
It is expected that the SQL Editor validates the NULLS NOT DISTINCT syntax correctly.
Additional context
There are 2 reports in discord but no bug reports here.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 16
Welp, it looks like
libpg-queryis not able to handleUNIQUE NULLS NOT DISTINCTyet either. I tried to parse the following table withinpgsql-parser:And I got the following error:
I’ll throw it in their issue board, but according to their repo, it seems parsing Postgres 15 is still in active development, but I’ll try to verify that just in case. But if this is just some feature that
libpg-queryneeds to develop before anything can work, then I’m afraid this is outside of my expertise until that’s done.No problem… happy I could help shed some light on it.
Woooo, that’s great! I actually don’t have my dev environment fully set up yet so I’ve been playing it by ear (or I guess eye) to trace the issue down.
I’ll see if I can work on this.
You’re right, it’s the postgres-meta repo.
Here’s a trace of the error.
The function is here.
Dependency of pgsql-parser is here.
In turn pgsql-parser has a dep of
"libpg-query": "13.3.1"here.The newest version of libpg-query is 15.02.
So I think that is the cause of this issue. Outdated sub dependency.
Edit, the pgsql-parser readme also confirms the compatibility up to postgres 13.