简体   繁体   English

根据 Redshift 中其他表的条目在表中插入值

[英]Insert values in a table based on entries of other table in Redshift

I have two tables in AWS Redshift and need to insert some values into one table based on the entries of the other.我在 AWS Redshift 中有两个表,需要根据另一个表的条目将一些值插入到一个表中。 I want to know if it is possible to accomplish the task using a AWS GLUE job, if so, will that be a good idea?我想知道是否可以使用 AWS GLUE 作业完成任务,如果可以,这是个好主意吗? Or should I use the query-editor/sqlworkbench in Redshift to accomplish the task.或者我应该使用 Redshift 中的 query-editor/sqlworkbench 来完成任务。

  • Table 1 has the following schema:表 1 具有以下架构:
Person(id,firstName,Lastname)
  • Table 2 has the following schema表 2 具有以下架构
Selection(perId,check)
  • If the concatenation of firstName and lastName of Person table lies in ['fullName1', 'fullName2',..] then then insert 1 in the selection table otherwise 0 with the respective id of person.如果 Person 表的firstNamelastName的串联位于['fullName1', 'fullName2',..]则在选择表中插入 1 否则为 0 并具有相应的 person id。

Example例子

  • the list values are: ['JohnLuie' , 'FranklinWatson']列表值为: ['JohnLuie' , 'FranklinWatson']

    person table人表

    Id   |        Firstname           |   lastName   
    04   |           John             |           Luie
    09   |           Ben              |         Johnson

Initially the Selection Table is empty.最初选择表是空的。 So after checking with the condition on person table That is if所以在检查人员表上的条件后,如果

  • (Person.firstName+ Person.lastName) in ['JohnLuie' , 'FranklinWatson] then insert 1 or 0 in Selection.check with person.id in Selection.perId (Person.firstName+ Person.lastName) in ['JohnLuie' , 'FranklinWatson]然后在 Selection.check 中插入 1 或 0 并在 Selection.perId 中使用 person.id

So after performing the task the Selection table will look like:因此,执行任务后,选择表将如下所示:

Selection选择

    PerId      |     check
     04        |        1
     09        |        0

I want to know if I can perform the following task by running aws-glue job.我想知道是否可以通过运行 aws-glue 作业来执行以下任务。 Both the tables are in redshift.两个表都处于红移状态。

You could just do it in an SQL query, something like:您可以在 SQL 查询中执行此操作,例如:

INSERT INTO Selection
(
    SELECT
      Id,
      CASE WHEN firstName || lastName IN ['JohnLuie' , 'FranklinWatson] THEN 1 ELSE 0 END
    FROM person
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM