我有一张桌子如下:
CREATE TABLE IF NOT EXISTS foo_raw
(
time TIMESTAMPTZ NOT NULL,
volume INTEGER, <-- note source field is of type integer
price DOUBLE PRECISION
);
COPY foo_raw(time,volume,price) FROM 'raw_data.csv' DELIMITER ',' CSV
然后我做一个
SELECT INTO
我正在合并一个新表
time
选择进入
SELECT
time,
SUM(volume)::integer AS volume, <-- note typecast to integer here
SUM(volume * price) / SUM(volume) AS price
INTO
foo
FROM
foo_raw
GROUP BY
time
ORDER BY
time;
如果我描述一下我的新桌子,我会发现
volume
字段的类型为
numeric
,不是
integer
.
pg=# \d foo
Table "public.foo"
Column | Type | Collation | Nullable | Default
--------+--------------------------+-----------+----------+---------
time | timestamp with time zone | | not null |
volume | numeric | | |
price | double precision | | |
你会在我的日记里记下
选择进入
我试着把结果打印出来
SUM(volume)
问题
如何强制字段为类型
整数
?