Maybe the first time I came into contact with select... into... from... and insert... select... many people may misunderstand that, on the surface, it is not that simple to query relevant information and add it to a table. Next, pig will introduce the differences between the two in the most common expression.
STEP/Method
1. First, let's take a look at the insert into select statement. Its Syntax format is: Insert into Table2 (field1, field2,...) select value1, value2,... from Table1.
2. The requirement here is that table 2 must already exist. If it does not exist, the system will prompt that the object is invalid.
3. Because Table2 already exists, we can add content that conforms to the column type to Table2 at will. Of course, it also includes constants. You may find that through the following figure, it is unusual to import constants.
4. Next, let's talk about the select into from statement. The syntax format is SELECT vale1, value2 into Table2 from Table1.
5. MyTable1 does not exist, because MyTable1 is automatically created during insertion. If MyTable1 has been created before, the system will prompt that the table already exists.
6. This feature will bring us a lot of convenience. First, if I only want to select the ID column in MyTable2, then add it to the new table.
7. If I want the Name column in MyTable2, I just need to select the Name column and add it to the new table.
END
Notes
The application scope is determined by the practitioners themselves ~