migrate
migrate copied to clipboard
postgres: current_schema: converting NULL to string is unsupported (empty search_path is NULL)
Describe the Bug
If the search_path is empty, CURRENT_SCHEMA() returns NULL but the reader tries to read a string so it fails with:
*database.Error: sql: Scan error on column index 0, name "current_schema": converting NULL to string is unsupported in line 0: SELECT CURRENT_SCHEMA()
Steps to Reproduce Steps to reproduce the behavior:
- Give it a DSN with empty search path
- Run migrate
- It will fail badly
Expected Behavior
Fail better returning ErrNoSchema, in https://github.com/golang-migrate/migrate/blob/14f6d3a92ff4c2581e60ca036375d737de047335/database/postgres/postgres.go#L99
Migrate Version v4.15.0
Loaded Database Drivers postgres
Go Version go version go1.17.2 darwin/arm64
Additional context
Should just scan into *string allowing nulls to work.
cq=# set search_path='';
SET
cq=# SELECT CURRENT_SCHEMA();
current_schema
----------------
(1 row)
cq=# SELECT CURRENT_SCHEMA() is null;
?column?
----------
t
(1 row)
Same as #692 which was closed
Hi @disq I am stucked in this issue..What may be the causes for this issue? Cant find any solution..
fixed in #914
Thanks @soyayaos for the fix! Closing this issue for now. Please reopen this if it's still not fixed