简体   繁体   中英

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. 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? Or should I use the query-editor/sqlworkbench in Redshift to accomplish the task.

  • Table 1 has the following schema:
Person(id,firstName,Lastname)
  • Table 2 has the following schema
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.

Example

  • the list values are: ['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

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. Both the tables are in redshift.

You could just do it in an SQL query, something like:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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