Greenplum:在表之间复制数据
Greenplum: copy data between tables
我需要从 table1 和 table 2 复制数据到 table3
我正在尝试执行此请求:
WITH sel AS (
SELECT
er.local_company_pk as "local_company_pk",
dv.load_dtm as "load_dtm",
dv.src as "rec_src",
dv.companyogrn as "ogrn",
dv."CompanyID" as "company_spark_id",
dv.companyvat as "company_vat",
dv."CompanyCountryCode" as "company_country_code",
dv."CompanyShortName" as "company_short_name",
dv."CompanyFullName" as "company_full_name",
dv."CompanySize" as "company_size",
dv."CompanyRevenue" as "company_revenue",
dv."StaffQuantity" as "staff_quantity",
dv."CompanyRegionName" as "company_region_name",
dv."CompanyCityName" as "company_city_name",
dv."RegistrationDT" as "registration_dt",
dv."EndDT" as "end_dt",
dv."CompanyStatus" as "company_status",
dv."FailureIndex" as "failure_index",
dv."IndexOfDueDiligence" as "index_of_due_diligence",
dv."ConsolidateIndex" as "consolidate_index",
' ' as "hash_diff"
FROM
table1 as dv,
table2 as er
WHERE
er.inn = dv.companyvat
LIMIT 10
)
INSERT INTO
table3
SELECT *
FROM sel
我有错误SQL Error [42601]: ERROR: syntax error at or near "INSERT"
如何在 table1 和 table2 之间从 select 插入到 table3?
为什么要使用 CTE?
INSERT INTO table3
SELECT
er.local_company_pk as "local_company_pk",
dv.load_dtm as "load_dtm",
dv.src as "rec_src",
dv.companyogrn as "ogrn",
dv."CompanyID" as "company_spark_id",
dv.companyvat as "company_vat",
dv."CompanyCountryCode" as "company_country_code",
dv."CompanyShortName" as "company_short_name",
dv."CompanyFullName" as "company_full_name",
dv."CompanySize" as "company_size",
dv."CompanyRevenue" as "company_revenue",
dv."StaffQuantity" as "staff_quantity",
dv."CompanyRegionName" as "company_region_name",
dv."CompanyCityName" as "company_city_name",
dv."RegistrationDT"::text as "registration_dt",
---------------------------^ you can cast the value
dv."EndDT" as "end_dt",
dv."CompanyStatus" as "company_status",
dv."FailureIndex" as "failure_index",
dv."IndexOfDueDiligence" as "index_of_due_diligence",
dv."ConsolidateIndex" as "consolidate_index",
' ' as hash_diff
FROM table1 as dv JOIN
table2 as er
ON er.inn = dv.companyvat
LIMIT 10
我还修复了你损坏的 JOIN
语法。
表3中的registration_dt是怎么定义的?如果它已经是一个日期,则无需将其投射到您的 SELECT 中。错误消息表明它被定义为日期。
我需要从 table1 和 table 2 复制数据到 table3 我正在尝试执行此请求:
WITH sel AS (
SELECT
er.local_company_pk as "local_company_pk",
dv.load_dtm as "load_dtm",
dv.src as "rec_src",
dv.companyogrn as "ogrn",
dv."CompanyID" as "company_spark_id",
dv.companyvat as "company_vat",
dv."CompanyCountryCode" as "company_country_code",
dv."CompanyShortName" as "company_short_name",
dv."CompanyFullName" as "company_full_name",
dv."CompanySize" as "company_size",
dv."CompanyRevenue" as "company_revenue",
dv."StaffQuantity" as "staff_quantity",
dv."CompanyRegionName" as "company_region_name",
dv."CompanyCityName" as "company_city_name",
dv."RegistrationDT" as "registration_dt",
dv."EndDT" as "end_dt",
dv."CompanyStatus" as "company_status",
dv."FailureIndex" as "failure_index",
dv."IndexOfDueDiligence" as "index_of_due_diligence",
dv."ConsolidateIndex" as "consolidate_index",
' ' as "hash_diff"
FROM
table1 as dv,
table2 as er
WHERE
er.inn = dv.companyvat
LIMIT 10
)
INSERT INTO
table3
SELECT *
FROM sel
我有错误SQL Error [42601]: ERROR: syntax error at or near "INSERT"
如何在 table1 和 table2 之间从 select 插入到 table3?
为什么要使用 CTE?
INSERT INTO table3
SELECT
er.local_company_pk as "local_company_pk",
dv.load_dtm as "load_dtm",
dv.src as "rec_src",
dv.companyogrn as "ogrn",
dv."CompanyID" as "company_spark_id",
dv.companyvat as "company_vat",
dv."CompanyCountryCode" as "company_country_code",
dv."CompanyShortName" as "company_short_name",
dv."CompanyFullName" as "company_full_name",
dv."CompanySize" as "company_size",
dv."CompanyRevenue" as "company_revenue",
dv."StaffQuantity" as "staff_quantity",
dv."CompanyRegionName" as "company_region_name",
dv."CompanyCityName" as "company_city_name",
dv."RegistrationDT"::text as "registration_dt",
---------------------------^ you can cast the value
dv."EndDT" as "end_dt",
dv."CompanyStatus" as "company_status",
dv."FailureIndex" as "failure_index",
dv."IndexOfDueDiligence" as "index_of_due_diligence",
dv."ConsolidateIndex" as "consolidate_index",
' ' as hash_diff
FROM table1 as dv JOIN
table2 as er
ON er.inn = dv.companyvat
LIMIT 10
我还修复了你损坏的 JOIN
语法。
表3中的registration_dt是怎么定义的?如果它已经是一个日期,则无需将其投射到您的 SELECT 中。错误消息表明它被定义为日期。