开发者

PostgreSQL: Casting two separate numeric values to a point

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-o开发者_如何学JAVArdinates 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜