带有 top 的普遍 SQL 更新
我希望这样做:
update aTable
set aField = 'value'
where aTable.Id in (select top 400 Id from aTable order by dateField) .
-- This will run, but it only updates the first id it gets to in the IN clause
或这样:
update top 400 aTable set aField = 'value' order by dateField
-- This will not run
但是,它必须在 Pervasive 的 V10 中工作...
类似的解决方法也足够了!
背景,我试图用按日期字段排序的值更新(项目的数量(可变))的字段。
这是 Pervasive 的更新帮助(我没有在那里看到 TOP 保留字):
UPDATE < table-name | view-name > [ alias-name ]
SET column-name = < NULL | DEFAULT
| expression | subquery-
expression > [ , column-name = ... ]
[ FROM table-reference [, table-reference ] ...
[ WHERE search-condition ]
table-name ::= user-defined-name
view-name ::= user-defined-name
alias-name ::= user-defined-name (Alias-name is not allowed if a
FROM clause is used. See FROM Clause .)
table-reference ::= { OJ outer-join-definition }
| [db-name.]table-name [ [ AS ] alias-name ]
| [db-name.]view-name [ [ AS ] alias-name ]
| join-definition | ( join-definition )
| ( table-subquery )[ AS ] alias-name [ (column-name [ , column-name
]... ) ]
I am looking to do this:
update aTable
set aField = 'value'
where aTable.Id in (select top 400 Id from aTable order by dateField) .
-- This will run, but it only updates the first id it gets to in the IN clause
or this:
update top 400 aTable set aField = 'value' order by dateField
-- This will not run
But, it has to work in V10 of Pervasive...
A similiar workaround would be sufficient too!
Background, I am trying to update a (number(which is variable) of items)'s field with a value ordered by a date field.
Here is Pervasive's Update help (I do not see the TOP reserved word in there):
UPDATE < table-name | view-name > [ alias-name ]
SET column-name = < NULL | DEFAULT
| expression | subquery-
expression > [ , column-name = ... ]
[ FROM table-reference [, table-reference ] ...
[ WHERE search-condition ]
table-name ::= user-defined-name
view-name ::= user-defined-name
alias-name ::= user-defined-name (Alias-name is not allowed if a
FROM clause is used. See FROM Clause .)
table-reference ::= { OJ outer-join-definition }
| [db-name.]table-name [ [ AS ] alias-name ]
| [db-name.]view-name [ [ AS ] alias-name ]
| join-definition | ( join-definition )
| ( table-subquery )[ AS ] alias-name [ (column-name [ , column-name
]... ) ]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我做了一些测试,实现此功能的最佳方法是创建一个视图:
然后使用Update中的视图:
我已经使用 PSQL v11 进行了测试,但它也应该适用于 PSQL v10。
I did some testing and the best way to get this working is to create a view:
Then use the view in the Update:
I've tested with PSQL v11 but it should also work with PSQL v10.