Insert

PostgreSQL Query: Insert

Example

Insert from another table

INSERT INTO target_table (column_list)
SELECT source_column_list
FROM source_table
WHERE condition;
INSERT INTO customer_backup (customer_id, customer_name, contact_name, address, city, postal_code, country)
SELECT customer_id, customer_name, contact_name, address, city, postal_code, country
FROM customers
WHERE country = 'Taiwan';

Insert from another table and assign the hard coded string

INSERT INTO TARGET_TABLE (id, col_1, col_2, col_3)
    SELECT id, 'hard', 'code', 'string'
    FROM SOURCE_TABLE
    WHERE status = 'something';

Reference