migrate icon indicating copy to clipboard operation
migrate copied to clipboard

postgres: current_schema: converting NULL to string is unsupported (empty search_path is NULL)

Open disq opened this issue 3 years ago • 2 comments
trafficstars

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:

  1. Give it a DSN with empty search path
  2. Run migrate
  3. 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)

disq avatar Feb 03 '22 17:02 disq

Same as #692 which was closed

disq avatar Feb 03 '22 17:02 disq

Hi @disq I am stucked in this issue..What may be the causes for this issue? Cant find any solution..

itissourav avatar Sep 12 '22 12:09 itissourav

fixed in #914

soyayaos avatar Apr 06 '23 21:04 soyayaos

Thanks @soyayaos for the fix! Closing this issue for now. Please reopen this if it's still not fixed

dhui avatar Apr 07 '23 05:04 dhui