在PostgreSQL中,您可以指定不带order by子句的frame子句。以下作品:
Option Explicit
Enum enumWatchType
WatchExpression
BreakWhenTrue
BreakWhenChange
End Enum
Enum enumProceduresType
AllProcedures
Caller
End Enum
Enum enumModuleType
AllModules
CurrentModule
ThisWorkbook
End Enum
Public testVar As Boolean
Sub HelloNewSession()
AddWatch "testVar = True", AllProcedures, CurrentModule, BreakWhenTrue
testVar = True
End Sub
Sub AddWatch( _
expression As String, _
Optional proceduresType As enumProceduresType = enumProceduresType.Caller, _
Optional moduleType As enumModuleType = enumModuleType.CurrentModule, _
Optional watchType As enumWatchType = enumWatchType.WatchExpression)
Dim i As Long
Application.SendKeys "%DA"
Application.SendKeys getEscapedSendkeysText(expression)
If proceduresType = enumProceduresType.AllProcedures Then
Application.SendKeys "%p"
For i = 1 To 1000 'You could use VBIDE to count the valid types to actually scroll up the right number of times!
Application.SendKeys "{UP}"
Next
End If
If moduleType = enumModuleType.AllModules Then
Application.SendKeys "%m"
For i = 1 To 1000 'You could use VBIDE to count the valid types to actually scroll up the right number of times!
Application.SendKeys "{UP}"
Next
ElseIf moduleType = enumModuleType.ThisWorkbook Then
Application.SendKeys "%m"
For i = 1 To 1000 'You could use VBIDE to count the valid types to actually scroll up the right number of times!
Application.SendKeys "{DOWN}"
Next
End If
Select Case watchType
Case enumWatchType.WatchExpression
Application.SendKeys "%w"
Case enumWatchType.BreakWhenTrue
Application.SendKeys "%t"
Case enumWatchType.BreakWhenChange
Application.SendKeys "%c"
End Select
Application.SendKeys "~"
End Sub
Function getEscapedSendkeysText(ByVal text As String) As String
Dim char As String, i As Long
Const chars As String = "~%+^()[]"
For i = 1 To Len(chars)
char = Mid$(chars, i, 1)
text = Replace(text, char, "{" & char & "}")
Next
getEscapedSendkeysText = text
End Function
在Oracle中,你不能这样做(你会得到“在窗口规范中通过表达式缺少ORDER”)。这对我来说很有意义 - 行没有排序,请求前后行是没有意义的。
阅读时docs create table dual (dummy character varying);
insert into dual values ('X');
select min(dummy) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND
UNBOUNDED FOLLOWING)
from dual;
select min(dummy) OVER (ROWS BETWEEN 1 PRECEDING AND 10 FOLLOWING)
from dual;
是可选的且独立于[frame_clause]
,但我不明白为什么这需要/有用。
为什么PostgreSQL允许这种行为?
答案 0 :(得分:1)
一个window子句是SELECT阶段的一部分,在查询处理的那个阶段实际上有一个行顺序。如果您没有指定order by
,那么它只是一个随机订单。
您可以做的一件事就是为方便起见,包括下一行的列,例如:
select id
, max(id) over (rows between 1 following and 1 following) as next_id
from AnyTable
按顺序读取行但由于某种原因需要下一行的id的客户端可以使用它。