我正在尝试将数据从 csv 文件导入 pg 表。我得到的错误是:
$ 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
我怎么知道它是关于哪个属性的?就此而言, INSERT 也失败了:
$ 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.
我试图根据\d users
输出和attnum
值进行计数:
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
我正在运行 PostgreSQL 12.7。