我正在使用另一个表dummy2
中的值创建表dummy
。这是我的语法:
CREATE TABLE dummy2 AS SELECT
t1.zid AS orig_id,
t2.zid AS dest_id,
ABS(RANDOM()*(45-2)-45) AS dist
FROM dummy t1, dummy t2;
zid
中的属性dummy
存储为DOUBLE PRECISION
。但是,在新表中,我想将其数据类型更改为INTEGER
。我怎样才能做到这一点?我最初的想法是这样的(非常类似于我们在使用模式创建表时声明数据类型的方式:
CREATE TABLE dummy2 AS SELECT
t1.zid AS orig_id INTEGER,
t2.zid AS dest_id INTEGER,
ABS(RANDOM()*(45-2)-45) AS dist
FROM dummy t1, dummy t2;
但它无法执行。任何人都可以帮我解决这个问题吗?感谢您的帮助!
答案 0 :(得分:2)
CREATE TABLE dummy2 AS SELECT
cast(t1.zid as integer) AS orig_id,
cast(t2.zid as integer) AS dest_id,
ABS(RANDOM()*(45-2)-45) AS dist
FROM dummy t1, dummy t2;