我想在table1中插入父行并设置其外部id,然后我想使用postgresql中父行中设置的外部id在同一个table1中插入子行。
我在子行中收到外部id不存在的错误。 有办法解决这个问题吗?
这些是我的疑问:
INSERT INTO salesforce.opportunity (Name,recordtypeid,StageName,closedate,person_account__r__externalid__c,externalid__c)
VALUES ('testMBexternalId5', '0120Y000000R4WEQA0', 'Qualification','2019-08-01','0014E00000hyqW5','test105');
INSERT INTO salesforce.opportunity (Name,recordtypeid,StageName,closedate,master_booking_fk__r__externalid__c)
VALUES ('test booking script225', '0120Y000000R4WJQA0', 'Qualification','2019-08-01', 'test105');
这是错误:
{"op": "INSERT", "src": "SFDC", "msg": "Foreign key external ID: test105 not found for field Externalid__c in entity Opportunity"}
。
这是表格的定义:
-- Table: salesforce.opportunity
-- DROP TABLE salesforce.opportunity;
CREATE TABLE salesforce.opportunity
(
first_status_fk__c character varying(255) COLLATE pg_catalog."default",
channel__c character varying(25) COLLATE pg_catalog."default",
person_account__c character varying(18) COLLATE pg_catalog."default",
utm_campaign__c character varying(20) COLLATE pg_catalog."default",
channelcategory__c character varying(40) COLLATE pg_catalog."default",
booking_id__c character varying(255) COLLATE pg_catalog."default",
contact__c character varying(18) COLLATE pg_catalog."default",
loss_reason__c character varying(255) COLLATE pg_catalog."default",
invoiced_amount__c double precision,
channel_description__c character varying(40) COLLATE pg_catalog."default",
rate__c character varying(25) COLLATE pg_catalog."default",
phone_numberbooking__c character varying(40) COLLATE pg_catalog."default",
trip_reason__c character varying(40) COLLATE pg_catalog."default",
firstnamebooking__c character varying(40) COLLATE pg_catalog."default",
deposit__c double precision,
pmsbookingid__c character varying(25) COLLATE pg_catalog."default",
master_booking_id__c character varying(255) COLLATE pg_catalog."default",
restart_date__c date,
bookingupdatable__c boolean,
closedate date,
recordtypeid character varying(18) COLLATE pg_catalog."default",
utm_term__c character varying(20) COLLATE pg_catalog."default",
pmsclientid__c character varying(25) COLLATE pg_catalog."default",
bookingerrorcode__c character varying(255) COLLATE pg_catalog."default",
accountid character varying(18) COLLATE pg_catalog."default",
checkindate__c date,
business_lead__c character varying(40) COLLATE pg_catalog."default",
source__c character varying(40) COLLATE pg_catalog."default",
stagename character varying(40) COLLATE pg_catalog."default",
phone_number__c character varying(40) COLLATE pg_catalog."default",
first_name__c character varying(255) COLLATE pg_catalog."default",
client_fk__c character varying(255) COLLATE pg_catalog."default",
max_departure__c date,
option_date__c date,
contact__r__externalid__c character varying(20) COLLATE pg_catalog."default",
bookingerrormessage__c character varying(255) COLLATE pg_catalog."default",
language__c character varying(25) COLLATE pg_catalog."default",
name character varying(120) COLLATE pg_catalog."default",
lastnamebooking__c character varying(40) COLLATE pg_catalog."default",
mobile_phone_number__c character varying(40) COLLATE pg_catalog."default",
lastmodifieddate timestamp without time zone,
trip_context__c character varying(40) COLLATE pg_catalog."default",
ownerid character varying(18) COLLATE pg_catalog."default",
last_name__c character varying(255) COLLATE pg_catalog."default",
checkoutdate__c date,
bookingsource__c character varying(40) COLLATE pg_catalog."default",
hotel__c character varying(18) COLLATE pg_catalog."default",
isdeleted boolean,
bookingcancellable__c boolean,
systemmodstamp timestamp without time zone,
account__externalid__c character varying(40) COLLATE pg_catalog."default",
lastmodifiedbyid character varying(18) COLLATE pg_catalog."default",
status__c character varying(25) COLLATE pg_catalog."default",
e_mail__c character varying(80) COLLATE pg_catalog."default",
master_booking_fk__r__externalid__c character varying(40) COLLATE pg_catalog."default",
crsbookingid__c character varying(40) COLLATE pg_catalog."default",
error_message__c character varying(255) COLLATE pg_catalog."default",
probability double precision,
creation_date__c date,
createddate timestamp without time zone,
current_status_fk__c character varying(255) COLLATE pg_catalog."default",
guarentee__c character varying(15) COLLATE pg_catalog."default",
utm_source__c character varying(20) COLLATE pg_catalog."default",
bookerdevice__c character varying(40) COLLATE pg_catalog."default",
min_arrival__c date,
prolongation__c date,
amount double precision,
cad_status__c character varying(20) COLLATE pg_catalog."default",
start_date__c date,
bookingstatus__c character varying(40) COLLATE pg_catalog."default",
nb_children__c double precision,
createdbyid character varying(18) COLLATE pg_catalog."default",
type character varying(40) COLLATE pg_catalog."default",
utm_content__c character varying(20) COLLATE pg_catalog."default",
opportunity_scope__c character varying(255) COLLATE pg_catalog."default",
email_addressbooking__c character varying(80) COLLATE pg_catalog."default",
master_booking_fk__c character varying(18) COLLATE pg_catalog."default",
distributionmode__c character varying(40) COLLATE pg_catalog."default",
externalid__c character varying(40) COLLATE pg_catalog."default",
payment_at_booking__c boolean,
bookingcomment__c character varying(255) COLLATE pg_catalog."default",
lost_against__c character varying(255) COLLATE pg_catalog."default",
hotel_id__c character varying(25) COLLATE pg_catalog."default",
utm_medium__c character varying(20) COLLATE pg_catalog."default",
hotel__r__hotel_id__c character varying(40) COLLATE pg_catalog."default",
partner_code__c character varying(15) COLLATE pg_catalog."default",
nb_adults__c double precision,
include_breakfast__c boolean,
distribution__c character varying(34) COLLATE pg_catalog."default",
error_code__c character varying(255) COLLATE pg_catalog."default",
sfid character varying(18) COLLATE pg_catalog."default",
id integer NOT NULL DEFAULT nextval('salesforce.opportunity_id_seq'::regclass),
_hc_lastop character varying(32) COLLATE pg_catalog."default",
_hc_err text COLLATE pg_catalog."default",
person_account__r__externalid__c character varying(40) COLLATE pg_catalog."default",
masterbookingexternalidbbus__c character varying(20) COLLATE pg_catalog."default",
CONSTRAINT opportunity_pkey PRIMARY KEY (id),
CONSTRAINT "OPP_EXTERNAL_ID" UNIQUE (externalid__c)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE salesforce.opportunity
OWNER to u7kra5fpd0kfj2;
GRANT INSERT, SELECT, UPDATE, DELETE, TRUNCATE ON TABLE salesforce.opportunity TO "TEST_USER";
GRANT ALL ON TABLE salesforce.opportunity TO u7kra5fpd0kfj2;
-- Index: hc_idx_opportunity_accountid
-- DROP INDEX salesforce.hc_idx_opportunity_accountid;
CREATE INDEX hc_idx_opportunity_accountid
ON salesforce.opportunity USING btree
(accountid COLLATE pg_catalog."default")
TABLESPACE pg_default;
-- Index: hc_idx_opportunity_contact__c
-- DROP INDEX salesforce.hc_idx_opportunity_contact__c;
CREATE INDEX hc_idx_opportunity_contact__c
ON salesforce.opportunity USING btree
(contact__c COLLATE pg_catalog."default")
TABLESPACE pg_default;
-- Index: hc_idx_opportunity_crsbookingid__c
-- DROP INDEX salesforce.hc_idx_opportunity_crsbookingid__c;
CREATE INDEX hc_idx_opportunity_crsbookingid__c
ON salesforce.opportunity USING btree
(crsbookingid__c COLLATE pg_catalog."default")
TABLESPACE pg_default;
-- Index: hc_idx_opportunity_hotel__c
-- DROP INDEX salesforce.hc_idx_opportunity_hotel__c;
CREATE INDEX hc_idx_opportunity_hotel__c
ON salesforce.opportunity USING btree
(hotel__c COLLATE pg_catalog."default")
TABLESPACE pg_default;
-- Index: hc_idx_opportunity_lastmodifieddate
-- DROP INDEX salesforce.hc_idx_opportunity_lastmodifieddate;
CREATE INDEX hc_idx_opportunity_lastmodifieddate
ON salesforce.opportunity USING btree
(lastmodifieddate)
TABLESPACE pg_default;
-- Index: hc_idx_opportunity_master_booking_fk__c
-- DROP INDEX salesforce.hc_idx_opportunity_master_booking_fk__c;
CREATE INDEX hc_idx_opportunity_master_booking_fk__c
ON salesforce.opportunity USING btree
(master_booking_fk__c COLLATE pg_catalog."default")
TABLESPACE pg_default;
-- Index: hc_idx_opportunity_person_account__c
-- DROP INDEX salesforce.hc_idx_opportunity_person_account__c;
CREATE INDEX hc_idx_opportunity_person_account__c
ON salesforce.opportunity USING btree
(person_account__c COLLATE pg_catalog."default")
TABLESPACE pg_default;
-- Index: hc_idx_opportunity_systemmodstamp
-- DROP INDEX salesforce.hc_idx_opportunity_systemmodstamp;
CREATE INDEX hc_idx_opportunity_systemmodstamp
ON salesforce.opportunity USING btree
(systemmodstamp)
TABLESPACE pg_default;
-- Index: hcu_idx_opportunity_externalid__c
-- DROP INDEX salesforce.hcu_idx_opportunity_externalid__c;
CREATE UNIQUE INDEX hcu_idx_opportunity_externalid__c
ON salesforce.opportunity USING btree
(externalid__c COLLATE pg_catalog."default")
TABLESPACE pg_default;
-- Index: hcu_idx_opportunity_sfid
-- DROP INDEX salesforce.hcu_idx_opportunity_sfid;
CREATE UNIQUE INDEX hcu_idx_opportunity_sfid
ON salesforce.opportunity USING btree
(sfid COLLATE pg_catalog."default")
TABLESPACE pg_default;
-- Trigger: BeforeInsertOpportunity
-- DROP TRIGGER "BeforeInsertOpportunity" ON salesforce.opportunity;
CREATE TRIGGER "BeforeInsertOpportunity"
BEFORE INSERT
ON salesforce.opportunity
FOR EACH ROW
EXECUTE PROCEDURE salesforce."SetExternalId"();
-- Trigger: hc_opportunity_logtrigger
-- DROP TRIGGER hc_opportunity_logtrigger ON salesforce.opportunity;
CREATE TRIGGER hc_opportunity_logtrigger
AFTER INSERT OR DELETE OR UPDATE
ON salesforce.opportunity
FOR EACH ROW
WHEN (((get_xmlbinary())::text = 'base64'::text))
EXECUTE PROCEDURE salesforce.hc_opportunity_logger();
-- Trigger: hc_opportunity_status_trigger
-- DROP TRIGGER hc_opportunity_status_trigger ON salesforce.opportunity;
CREATE TRIGGER hc_opportunity_status_trigger
BEFORE INSERT OR UPDATE
ON salesforce.opportunity
FOR EACH ROW
EXECUTE PROCEDURE salesforce.hc_opportunity_status();
我可以插入行父行,然后是行子行,还是有另一个解决方案?