我已经使用pg_dump --column-inserts -h localhost -U postgres micro -a -F p > /tmp/new_backup_data.sql
将postgresql db上的数据备份到了'new_backup_data.sql'中,然后我想将数据恢复到已经具有相同模式表的其他数据库上,触发。 psql -U postgres micro < /tmp/new_backup_data.sql
但是触发器总是使它失败。这是错误:
QUERY: SELECT LPAD(cast(cast(substring(registration_code, 10) AS integer) + 1 AS varchar), 4, '0')
FROM t_registration
ORDER BY id
DESC LIMIT 1
CONTEXT: PL/pgSQL function public.generate_registration_code() line 7 at SQL statement
ERROR: relation "t_registration" does not exist
LINE 2: FROM t_registration
^
QUERY: SELECT LPAD(cast(cast(substring(registration_code, 10) AS integer) + 1 AS varchar), 4, '0')
FROM t_registration
ORDER BY id
DESC LIMIT 1
CONTEXT: PL/pgSQL function public.generate_registration_code() line 7 at SQL statement
ERROR: relation "t_registration" does not exist
LINE 2: FROM t_registration
^
QUERY: SELECT LPAD(cast(cast(substring(registration_code, 10) AS integer) + 1 AS varchar), 4, '0')
FROM t_registration
ORDER BY id
DESC LIMIT 1
CONTEXT: PL/pgSQL function public.generate_registration_code() line 7 at SQL statement
ERROR: relation "t_registration" does not exist
LINE 2: FROM t_registration
以下是我尝试打开备份sql文件时的查询:
INSERT INTO public.t_registration (id, created_by, created_date, last_modified_by, last_modified_date, is_active, registration_code, registration_type_code, app_id, app_code, account_code) VALUES (94, 'Admin', '2020-07-16 09:04:32.095', 'Admin', '2020-07-16 09:04:32.095', true, 'REG2007160001', 'R2007001', 1, 'APP202007001', NULL);
当我通过PG管理员手动运行查询时,它可以正常工作并且触发器没有问题,但是为什么在还原时总是会产生那些错误?
注意:我的触发器用于生成唯一代码的模式
答案 0 :(得分:2)
查看转储文件的顶部。我猜你有类似SELECT pg_catalog.set_config('search_path', '', false);
的东西,这使search_path
成为空白。由于函数中的表名不是架构限定的,因此找不到。在此处设置search_path
的情况下,pgAdmin的情况起作用。仅供参考,转储文件正在使用COPY
提取数据。但这仍然会触发触发器。
更新。要修复模式,请在函数中限定表名。