У меня есть следующие таблицы:Postgres ошибка "ERROR: INSERT имеет несколько целевых столбцов, чем выражения"
CREATE TABLE public.participant_audit
(
participant_audit_id bigint NOT NULL DEFAULT nextval('participant_audit_participant_audit_id_seq'::regclass),
participant_id bigint,
shared_asset_id bigint NOT NULL,
asset_role_type character varying(200) NOT NULL,
user_external_ref_uuid uuid NOT NULL,
user_first_name character varying(200) NOT NULL,
user_last_name character varying(200) NOT NULL,
user_email_address character varying(200) NOT NULL,
deleted_timestamp timestamp(0) with time zone,
row_updated_timestamp timestamp(6) with time zone NOT NULL,
row_created_timestamp timestamp(6) with time zone NOT NULL,
row_created_by_db_user oid NOT NULL,
row_updated_by_db_user oid NOT NULL,
created_by_client uuid,
updated_by_client uuid,
CONSTRAINT participant_audit_pkey PRIMARY KEY (participant_audit_id)
)
WITH (
OIDS=FALSE
);
CREATE TABLE public.participant
(
participant_id bigint NOT NULL DEFAULT nextval('participant_participant_id_seq'::regclass),
shared_asset_id bigint NOT NULL,
asset_role_type_id bigint NOT NULL,
user_external_ref_uuid uuid NOT NULL,
user_first_name character varying(200) NOT NULL,
user_last_name character varying(200) NOT NULL,
user_email_address character varying(200) NOT NULL,
deleted_timestamp timestamp(0) with time zone,
row_updated_timestamp timestamp(6) with time zone NOT NULL,
row_created_timestamp timestamp(6) with time zone NOT NULL,
row_created_by_db_user oid NOT NULL,
row_updated_by_db_user oid NOT NULL,
created_by_client uuid,
updated_by_client uuid,
CONSTRAINT participant_pkey PRIMARY KEY (participant_id),
CONSTRAINT participant_asset_role_type_id_fkey FOREIGN KEY (asset_role_type_id)
REFERENCES public.asset_role_type (asset_role_type_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT participant_shared_asset_id_fkey FOREIGN KEY (shared_asset_id)
REFERENCES public.shared_asset (shared_asset_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
И следующий TRIGGER ФУНКЦИЯ:
-- DROP FUNCTION public.participant_audit();
CREATE OR REPLACE FUNCTION public.participant_audit()
RETURNS trigger AS
$BODY$
BEGIN
insert into participant_audit
(participant_audit_id, participant_id , shared_asset_id , asset_role_type , user_external_ref_uuid,
user_first_name , user_last_name , user_email_address , deleted_timestamp, row_updated_timestamp,
row_created_timestamp , row_created_by_db_user , row_updated_by_db_user , created_by_client,
updated_by_client
)
select NEW.* ;
RETURN NEW;
END;
$BODY$
LANGUAGE plpgsql VOLATILE SECURITY DEFINER
COST 100;
Когда я выполнить следующий INSERT
INSERT INTO participant (shared_asset_id,asset_role_type_id,
user_external_ref_uuid,user_first_name,user_last_name,
user_email_address,row_created_by_db_user,
row_updated_by_db_user,created_by_client,updated_by_client)
VALUES (1, 1, 'c9d140ad-b0da-4a9d-a898-8719000c7b7b'::uuid , 'john', 'simpson', '[email protected]', 1::oid,1::oid, '53ed670d-f680-4e81-b53d-59b3d487633f'::uuid, '53ed670d-f680-4e81-b53d-59b3d487633f'::uuid);
Я получаю следующее сообщение об ошибке:
ERROR: INSERT has more target columns than expressions LINE 2: ...user , row_updated_by_db_user , created_by_client,updated_by... ^QUERY: insert into public.participant_audit (participant_audit_id, participant_id , shared_asset_id , asset_role_type , user_external_ref_uuid,user_first_name , user_last_name , user_email_address , deleted_timestamp, row_updated_timestamp,row_created_timestamp , row_created_by_db_user , row_updated_by_db_user , created_by_client,updated_by_client) select NEW.* CONTEXT: PL/pgSQL function participant_audit() line 3 at SQL statement
********** Error **********
ERROR: INSERT has more target columns than expressions SQL state: 42601 Context: PL/pgSQL function participant_audit() line 3 at SQL statement
Как исправить эту проблему?
Вы не добавляете достаточно столбцов в свой 'insert'. Либо удалите 'updated_by_client' из before' values', либо добавьте значение для' updated_by_client' –
. Я выполнил следующее и все еще получил вышеуказанную ошибку: 'INSERT INTO участник (shared_asset_id, asset_role_type_id, user_external_ref_uuid, user_first_name, user_last_name, user_email_address, row_created_by_db_user, row_updated_by_db_user) значения (1, 1, 'c9d140ad-b0da-4a9d-a898-8719000c7b7b' :: uuid, 'john', 'simpson', '[email protected]', 1 :: oid, 1: oid); ' – XnaijaZ
Я не думаю, что вы хотели пометить этот ['plsql'] (http://stackoverflow.com/tags/plsql/info), поскольку вопрос не имеет ничего общего с Oracle. –