Estou tentando importar dados para uma tabela pg de um arquivo csv. O erro que recebo é:
$ psql -U postgres -c "COPY users (first_name) FROM '/users.csv' (FORMAT csv)"
ERROR: attribute 51 of type users has wrong type
DETAIL: Table has type integer, but query expects character varying.
CONTEXT: COPY users, line 1
Como saber de qual atributo se trata? Por esse motivo, um INSERT também falha:
$ psql -U postgres -c "INSERT INTO users (first_name) VALUES ('first_name')"
ERROR: attribute 51 of type record has wrong type
DETAIL: Table has type integer, but query expects character varying.
Tentei contar de acordo com a \d users
saída e com o attnum
valor:
SELECT a.*
FROM pg_attribute a
JOIN pg_class c on a.attrelid = c.oid
JOIN pg_namespace n on c.relnamespace = n.oid
WHERE n.nspname = 'public'
AND c.relname = 'users'
AND attnum >= 1
ORDER BY attnum
Estou executando o PostgreSQL 12.7.