I am using PostgreSQL 9.2. I need to copy the addresses (which are split across multiple columns) from this table entitled houses:
house_id | unit_number| street_number | street| street_extension| suburb | postcode | state | sale_price | sale_date |
----------+------------+-------+-------+-------+-----------------+--------+----------+-------+------------+-----------+
1 | 2 | 17 | Rose | Av | Rye | 3099 | VIC | 240000 | 2003-12-02|
2 | | 3 | Jack | St | Rye | 3099 | VIC | 260000 | 2003-10-02|
into a single column in this table entitled address_list:
house_id | address | formatted_address | lat | lon | wkb_geometry | is_processed
----------+------------------------------------------+-------------------+-----+-----+--------------+--------------
| | | | | |
| | | | | |
My syntax is
INSERT INTO address_list (house_id, address)
SELECT house_id, unit_number || '/' || street_number || ' ' || street || ' ' || street_extension || ', ' || suburb || ', ' || state || ' ' || postcode
FROM houses;
My syntax does not work because of some null entries in the unit_number field of the source table.
Is there a way of copying the unit_number plus a "\" if NOT NULL, and ignoring the unit_number field and the "\" IF NULL?
I have spent several hours searching for a solution without luck so I would be extremely grateful for any assistance.