-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: current_schema should skip over invalid schemas #24472
Comments
To reproduce you could simply do
and just run
|
Seems to be an issue with the query
After that the create queries fail. |
Have published a patch for my cockroachdb driver db-migrate/cockroachdb@ce29dca You have to use version |
@wzrdtales you mention your client sends |
Even in PostgreSQL the same search path would cause the same error if the |
@wzrdtales looking at your code, I understand this SET statement is issued by the baseline library that your code is overloading. Can you share with us the exact text of the SET statement sent by the client / received by the server? You can use the execution log for this ( |
@knz I see, I guess I need to explain a bit more.
What you changed from version 1 to version 2 was, that So to provide you the exact statements,you actually can reproduce those with the instruction above. However here you go:
|
That's not true, empirically - I just tried it. The core incompatibility here is that Postgres permits search paths that contain nonexistent schemas, and CockroachDB doesn't. We should just fix that.
See https://www.postgresql.org/docs/9.1/static/ddl-schemas.html and https://www.postgresql.org/docs/9.1/static/runtime-config-client.html. @wzrdtales you will need to change the |
There is already a patch online that fixes that issue for my driver, just staying here to figure out with you what needs to be done on your side :) And your mentioning of So the assumption made here is, that the db name is equivalent to schema which would correctly resolve to |
So I would suggest at least documenting this changes from v1 to v2 and making clear that the db name is not anymore equal to the schema name. |
@jordanlewis please check again:
CockroachDB does the same, to search for existing objects. The issue here is the attempt to create a table. Both CockroachDB and PostgreSQL create objects in the "current schema" (= the first item in |
@knz, no, unfortunately that's false (with regards to creating new tables). I'll demonstrate:
|
Here's what I'm referring to: https://www.postgresql.org/docs/10/static/sql-createtable.html
|
Separately, in https://www.postgresql.org/docs/10/static/functions-info.html
|
Ah, apparently the docs are lying - it seems
|
Ok thanks for figuring that out. Changing the definition of the current schema in CockroachDB to align with pg is much easier than changing the name resolution rules. |
24718: sql: fix the handling of current_schema and search_path r=knz a=knz Fixes #24472. Prior to this patch, CockroachDB was following the pg docs to the letter regarding the relationship between `search_path` and the "current schema": the current schema was taken to always be the first item in `search_path`, as indicated in https://www.postgresql.org/docs/9.6/static/functions-info.html ("current_schema returns the name of the schema that is first in the search path (or a null value if the search path is empty).") This in turn impacts the creation of objects (tables, views, etc) when the name is unqualified: pg also specifies that such objects are to be created in the current schema. Unfortunately the pg doc is incorrect, as pg has a more nuanced behavior: only the _valid_ schemas in `search_path` are considered to determine the current schema in that way. This was causing an unfortunate visible compatibility bug: if the user specified an invalid schema in the search path, subsequent create operations would fail with CockroachDB and succeed with pg. This patch corrects this issue by adopting pg's behavior. Ditto for `current_schemas`. Release note (sql change, bug fix): the built-in functions `current_schema` and `current_schemas` now only consider valid schemas, like PostgreSQL does. Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
BUG REPORT
For cockroachdb 2.0.0 the node driver fails to create a table for unknown reasons when using it with db-migrate:
If you execute the same query by hand, it does work for unknown reasons:
On my side everything is patched now:
db-migrate/cockroachdb@ce29dca
The text was updated successfully, but these errors were encountered: