触发器(用于生成的代码)在 postgresql 上执行恢复数据时产生错误
Triggers (for generated code) produce error when doing restore data on postgresql
我已经使用 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 admin 手动查询时它工作并且触发器没有问题,但为什么当我恢复它时总是产生这些错误?
注意:我的触发器用于生成唯一代码的模式
查看转储文件的顶部。我猜你有类似 SELECT pg_catalog.set_config('search_path', '', false);
的内容,这会空白 search_path
。由于函数中的 table 名称不是架构限定的,因此找不到。 pgAdmin 案例的工作原理是 search_path
设置在那里。仅供参考,转储文件使用 COPY
提取数据。尽管如此,这仍然会触发触发器。
更新。要修复架构,请在函数中限定 table 名称。
我已经使用 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 admin 手动查询时它工作并且触发器没有问题,但为什么当我恢复它时总是产生这些错误?
注意:我的触发器用于生成唯一代码的模式
查看转储文件的顶部。我猜你有类似 SELECT pg_catalog.set_config('search_path', '', false);
的内容,这会空白 search_path
。由于函数中的 table 名称不是架构限定的,因此找不到。 pgAdmin 案例的工作原理是 search_path
设置在那里。仅供参考,转储文件使用 COPY
提取数据。尽管如此,这仍然会触发触发器。
更新。要修复架构,请在函数中限定 table 名称。