Skip to content

Atlasでpostgres: unexpected number of rows: 1というエラーになる

atlas migrate status などPostgreSQLにアクセスする箇所でエラーが発生する。

Terminal window
$ atlas migrate status \
--dir 'file://ent/migrate/migrations' \
--url 'postgres://lufia@localhost:5432/database?search_path=public&sslmode=disable'
Error: postgres: unexpected number of rows: 1

エラーの発生源はこれ。

原因は、おそらく go install でインストールされる atlas のバージョンが古いから。

2023年10月頃にConnect to Postgres docker image results in error “postgres: unexpected number of rows: 1”というイシューがあって、それ自体は修正されているが、Go Modulesのバージョンがv0.13のまま更新されていない

上記イシューに「バージョン更新してくれ」とコメントしたけど、公式のインストールスクリプトを使ってくれとのことだった。しかしシェルにパイプするスタイルのインストーラが嫌いなので公式インストーラは実行したくない。

原因から分かるように、新しいバージョンをインストールすればよい。

git clone して cd atlas/cmd/atlas && go install でもいいし、Arch LinuxならAURがあるのでパッケージとしてインストールしてもいい。