Skip to content

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

@disq

Description

@disq

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

return nil, ErrNoSchema

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions