admin管理员组文章数量:1415460
I want to update some values on a table using the VALUES
syntax, as supported by INSERT
. When I try this I get an error saying ) expected
update t
SET
name = myvalues.name
FROM (
VALUES
(1, 'textA'),
(2, 'textB')
) AS myvalues (id, name)
WHERE t.id = myvalues.id
My table schema is like this
create table t (
timestamp timestamp,
id symbol,
name varchar,
price float
) timestamp(timestamp) partition by day DEDUP UPSERT KEYS(timestamp, id);
And I can insert values with the VALUES
syntax as in:
insert into t
values
( rnd_timestamp(to_timestamp('2025-02-21', 'yyyy-MM-dd'), to_timestamp('2025-02-21T01:00:00', 'yyyy-MM-ddTHH:mm:ss'), 0), 'APPL', 'apple', 102.1),
( rnd_timestamp(to_timestamp('2025-02-21', 'yyyy-MM-dd'), to_timestamp('2025-02-21T01:00:00', 'yyyy-MM-ddTHH:mm:ss'), 0), 'GOOG', 'google', 45),
( rnd_timestamp(to_timestamp('2025-02-21', 'yyyy-MM-dd'), to_timestamp('2025-02-21T01:00:00', 'yyyy-MM-ddTHH:mm:ss'), 0), 'APPL', 'apple', 102.1),
( rnd_timestamp(to_timestamp('2025-02-21', 'yyyy-MM-dd'), to_timestamp('2025-02-21T01:00:00', 'yyyy-MM-ddTHH:mm:ss'), 0), 'APPL', 'apple', 102.3),
( rnd_timestamp(to_timestamp('2025-02-21', 'yyyy-MM-dd'), to_timestamp('2025-02-21T01:00:00', 'yyyy-MM-ddTHH:mm:ss'), 0), 'GOOG', 'google', 45.1),
( rnd_timestamp(to_timestamp('2025-02-21', 'yyyy-MM-dd'), to_timestamp('2025-02-21T01:00:00', 'yyyy-MM-ddTHH:mm:ss'), 0), 'MSFT', 'microsoft', 70);
What would be the proper way to run the update?
I want to update some values on a table using the VALUES
syntax, as supported by INSERT
. When I try this I get an error saying ) expected
update t
SET
name = myvalues.name
FROM (
VALUES
(1, 'textA'),
(2, 'textB')
) AS myvalues (id, name)
WHERE t.id = myvalues.id
My table schema is like this
create table t (
timestamp timestamp,
id symbol,
name varchar,
price float
) timestamp(timestamp) partition by day DEDUP UPSERT KEYS(timestamp, id);
And I can insert values with the VALUES
syntax as in:
insert into t
values
( rnd_timestamp(to_timestamp('2025-02-21', 'yyyy-MM-dd'), to_timestamp('2025-02-21T01:00:00', 'yyyy-MM-ddTHH:mm:ss'), 0), 'APPL', 'apple', 102.1),
( rnd_timestamp(to_timestamp('2025-02-21', 'yyyy-MM-dd'), to_timestamp('2025-02-21T01:00:00', 'yyyy-MM-ddTHH:mm:ss'), 0), 'GOOG', 'google', 45),
( rnd_timestamp(to_timestamp('2025-02-21', 'yyyy-MM-dd'), to_timestamp('2025-02-21T01:00:00', 'yyyy-MM-ddTHH:mm:ss'), 0), 'APPL', 'apple', 102.1),
( rnd_timestamp(to_timestamp('2025-02-21', 'yyyy-MM-dd'), to_timestamp('2025-02-21T01:00:00', 'yyyy-MM-ddTHH:mm:ss'), 0), 'APPL', 'apple', 102.3),
( rnd_timestamp(to_timestamp('2025-02-21', 'yyyy-MM-dd'), to_timestamp('2025-02-21T01:00:00', 'yyyy-MM-ddTHH:mm:ss'), 0), 'GOOG', 'google', 45.1),
( rnd_timestamp(to_timestamp('2025-02-21', 'yyyy-MM-dd'), to_timestamp('2025-02-21T01:00:00', 'yyyy-MM-ddTHH:mm:ss'), 0), 'MSFT', 'microsoft', 70);
What would be the proper way to run the update?
Share Improve this question asked Feb 21 at 17:42 Javier RamirezJavier Ramirez 4,0951 gold badge27 silver badges36 bronze badges1 Answer
Reset to default 0Since we are using DEDUP
on the table, one efficient way of doing this is by re-inserting the affected rows with the updated value.
Since we want to join with the value list, we can do first a UNION
with the selected values, then JOIN
with the original table, and do an INSERT INTO
from that subquery.
with vals AS (
SELECT 'APPL' as id, 'APPLE Inc' as name
UNION
SELECT 'GOOG' as id, 'Google' as name
), updated AS (
SELECT
t.timestamp, t.id, vals.name as name, t.price
FROM
t JOIN vals
ON(id)
)
INSERT BATCH 100000 INTO t (timestamp, id, name, price) SELECT * FROM updated;
本文标签: databaseUPDATE on QuestDB using VALUES syntaxStack Overflow
版权声明:本文标题:database - UPDATE on QuestDB using VALUES syntax - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745163098a2645540.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论