问题描述
我有两个表:Postgresql数据库中的Records
和Notifications
逻辑流程是,我将收到许多消息,这些消息将存储在Notifications
表中。有时,我将所有通知按公共标识符分组,然后将该标识符作为主键,将一行存储到Records
表中。
问题是,以后,我可能仍会收到带有相同标识符的通知,但是如果我已经为其创建了一条记录,我想忽略它们。
所以我的问题是-只有在标识符未出现在notifications
表中的情况下,有没有办法很好地有条件地插入Records
中?我在想一个“反向外键”,如果一列确实出现在另一个表中,它将无法插入。
我知道此sql无效,但我正在尝试使这种情况发生:
INSERT INTO notifications (id,notification,timestamp)
values (:id,:notification,Now())
WHERE records DOES NOT HAVE :id
解决方法
您可以使用beta:
ldr r3,.L6
ldr r1,.L6+4
add ip,r3,#400
.L2:
ldr r2,[r3,#4]!
ldr r0,[r1,#4]!
cmp r3,ip
add r2,r2,r0
str r2,[r3]
bne .L2
bx lr
.L6:
.word a-4
.word b-4
alpha:
ldr r3,.L13
ldr r2,.L13+4
push {r4,r5,r6,r7,r8,lr}
add r7,#400
.L9:
ldr lr,[r3]
ldr ip,#4]
ldr r0,#8]
ldr r1,#12]
ldr r8,[r2]
ldr r6,[r2,#4]
ldr r5,#8]
ldr r4,#12]
add lr,lr,r8
add ip,ip,r6
add r0,r0,r5
add r1,r1,r4
str lr,[r3]
str ip,#4]
str r0,#8]
str r1,#12]
add r3,#16
cmp r3,r7
add r2,#16
bne .L9
pop {r4,pc}
.L13:
.word a
.word b
语句来表达这一点:
insert ... select