0

我正在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;

但它无法执行。谁能帮我解决这个问题?感谢帮助!

4

1 回答 1

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;
于 2012-10-06T11:40:32.807 回答