Chapter 4 Migrating SQL Statements
---
This chapter explains how to migrate SQL statements.
### 4.1 Partitions
This section provides examples of migrating partitions.
#### 4.1.1 Partition Tables
**Description**
Partitions split tables and indexes into smaller units for management.
The following example shows conversion of an Oracle database partition to child tables in PostgreSQL. All migration examples provided here are based on this table.
**Example of tables created by partitioning inventory_table**
| i_number
(product code) | i_name
(category) | i_quantity
(inventory quantity) | i_warehouse
(warehouse code) |
| :---: | :--- | :---: | :---: |
| SMALLINT
PRIMARY KEY | VARCHAR(20)
NOT NULL | INTEGER | SMALLINT |
| 123 | refrigerator | 60 | 1 |
| 124 | refrigerator | 75 | 1 |
| 226 | refrigerator | 8 | 1 |
| 227 | refrigerator | 15 | 1 |
| 110 | television | 85 | 2 |
| 111 | television | 90 | 2 |
| 140 | cd player | 120 | 2 |
| 212 | television | 0 | 2 |
| 215 | Video | 5 | 2 |
| 240 | cd player | 25 | 2 |
| 243 | cd player | 14 | 2 |
| 351 | Cd | 2500 | 2 |
**Functional differences**
- **Oracle database**
- Partition tables can be created.
- **PostgreSQL**
- Partition tables cannot be created.
**Migration procedure**
Use the following procedure to perform migration:
1. Search for the keyword PARTITION and identify where CREATE TABLE is used to create a partition.
2. Delete the PARTITION clause and following lines from the CREATE TABLE statement and create a table.
3. Create a child table that inherits the table defined in step 1, and add table constraints to the split table for defining partition constraints.
4. Define a trigger or rule so that data inserted to the table is assigned to the appropriate child table.
**Migration example**
The example below shows migration when partitions are created in inventory_table.
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|
Oracle database | PostgreSQL |
---|---|
|
|