views:

32

answers:

1

I'm trying to change the application schema of a database in Postgres...so I need to copy data from one table to another. In the original table, co-ordinates are specified as numeric values in two separate columns, one for the x value and one for the y value. In the new table, the co-ordinates need to be stored as one value of the point data type. How would I cast the two separate numeric values into one that is a point?

+2  A: 

You should be able to do:

INSERT INTO New_Table (my_id, my_point)
SELECT
    my_id,
    POINT(x, y)
FROM
    Old_Table

I don't have PostgreSQL on my machine here, so I can't test it, but I think that's the syntax.

X and Y are supposed to be double precision numerics. I don't know what your X and Y data types are and I don't know what implicit conversions PostgreSQL will do for you, so you may need to do a convert there as well.

Tom H.