Y-combinator是一种来自事物"功能"方面的计算机科学概念.大多数程序员对组合器一无所知,如果他们甚至听说过它们的话.
theory computer-science functional-programming combinators definition
请帮我理解背后的用例SELECT ... FOR UPDATE
.
问题1:以下是SELECT ... FOR UPDATE
应该何时使用的一个很好的例子?
鉴于:
该应用程序希望列出所有房间及其标签,但需要区分没有标签的房间与已移除的房间.如果未使用SELECT ... FOR UPDATE,可能发生的情况是:
[id = 1]
[id = 1, name = 'cats']
[room_id = 1, tag_id = 1]
SELECT id FROM rooms;
returns [id = 1]
DELETE FROM room_tags WHERE room_id = 1;
DELETE FROM rooms WHERE id = 1;
SELECT tags.name FROM room_tags, tags WHERE room_tags.tag_id = 1 AND tags.id …
我使用备份
pg_dump db_production > postgres_db.dump
Run Code Online (Sandbox Code Playgroud)
然后我使用scp将其复制到localhost.
现在,当我导入我的本地数据库时,它会出错
pg_restore: [archiver] input file appears to be a text format dump. Please use psql.
Run Code Online (Sandbox Code Playgroud)
通过使用commad行
pg_restore -d db_development postgres_db.dump
Run Code Online (Sandbox Code Playgroud) 关于在Postgres函数中使用SELECT ... FOR UPDATE行级锁定,我有两个问题:
我选择哪一列是否重要?他们与我需要锁定然后更新的数据有什么关系吗?
SELECT * FROM table WHERE x=y FOR UPDATE;
Run Code Online (Sandbox Code Playgroud)
VS
SELECT 1 FROM table WHERE x=y FOR UPDATE;
Run Code Online (Sandbox Code Playgroud)我不能在没有保存数据的情况下在函数中进行选择,所以我保存为虚拟变量.这似乎是hacky; 这是正确的做事方式吗?
这是我的功能:
CREATE OR REPLACE FUNCTION update_message(v_1 INTEGER, v_timestamp INTEGER, v_version INTEGER)
RETURNS void AS $$
DECLARE
v_timestamp_conv TIMESTAMP;
dummy INTEGER;
BEGIN
SELECT timestamp 'epoch' + v_timestamp * interval '1 second' INTO v_timestamp_conv;
SELECT 1 INTO dummy FROM my_table WHERE userid=v_1 LIMIT 1 FOR UPDATE;
UPDATE my_table SET (timestamp) = (v_timestamp_conv) WHERE userid=v_1 AND version < v_version; …
Run Code Online (Sandbox Code Playgroud) 我最近在我的笔记本电脑上安装了 pgadmin4,当我启动应用程序时,它只是卡在加载中。我查看了日志,这就是我所看到的:
日志
2020-11-14 00:22:46: Checking for system tray...
2020-11-14 00:22:46: Starting pgAdmin4 server...
2020-11-14 00:22:46: Creating server object, port:64222, key:2a079549-63da-44d2-8931-efa9de3a847f, logfile:C:/Users/yonis/AppData/Local/pgadmin4.d41d8cd98f00b204e9800998ecf8427e.log
2020-11-14 00:22:46: Python Path: C:/Program Files/PostgreSQL/13/pgAdmin 4/venv/Lib/site-packages;C:/Program Files/PostgreSQL/13/pgAdmin 4/venv/DLLs;C:/Program Files/PostgreSQL/13/pgAdmin 4/venv/Lib
2020-11-14 00:22:46: Python Home: C:/Program Files/PostgreSQL/13/pgAdmin 4/venv
2020-11-14 00:22:46: Initializing Python...
2020-11-14 00:22:46: Python initialized.
2020-11-14 00:22:46: Adding new additional path elements
2020-11-14 00:22:46: Redirecting stderr...
2020-11-14 00:22:46: stderr redirected successfully.
2020-11-14 00:22:46: Initializing server...
2020-11-14 00:22:46: Webapp Path: C:/Program Files/PostgreSQL/13/pgAdmin 4/web/pgAdmin4.py
2020-11-14 00:22:46: Server initialized, starting …
Run Code Online (Sandbox Code Playgroud) 我正在寻找在SQLAlchemy中使用select for update的完整示例,但是没有找到一个谷歌搜索.我需要锁定单行并更新列,以下代码不起作用(永久阻塞):
s = table.select(table.c.user=="test",for_update=True)
# Do update or not depending on the row
u = table.update().where(table.c.user=="test")
u.execute(email="foo")
Run Code Online (Sandbox Code Playgroud)
我需要提交吗?我怎么做?据我所知,你需要:开始事务选择...用于更新更新提交
我正在使用 PostgresSQL,并且尝试删除列中的所有数据(我的实体由 和 组成id
)name
,但是当我运行代码时,会出现一条错误消息。
这是代码(我使用 NestJs 和 TypeOrm):
@Injectable()
export class ClearLinioBrands {
constructor(
@InjectRepository(LinioBrand)
private linioBrandRepo: Repository<LinioBrand>,
) {}
async execute(): Promise<void> {
const existingBrands = await this.linioBrandRepo.find();
await this.linioBrandRepo.remove(existingBrands);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我在控制台上收到以下错误:
@Injectable()
export class ClearLinioBrands {
constructor(
@InjectRepository(LinioBrand)
private linioBrandRepo: Repository<LinioBrand>,
) {}
async execute(): Promise<void> {
const existingBrands = await this.linioBrandRepo.find();
await this.linioBrandRepo.remove(existingBrands);
}
}
Run Code Online (Sandbox Code Playgroud)
该表中有 115900 行,这是此行为的原因吗?我应该怎么办?
我正在尝试将SQL内部联接查询转换为PostgreSQL内部联接查询。在此内部联接查询中,正在使用哪些表,即所有表都不在一个数据库中。我们将表分为两个数据库,即应用程序数据库和安全性数据库
我尝试如下所示,但出现以下错误
错误
ERROR: cross-database references are not implemented: "Rockefeller_ApplicationDb.public.userrolemapping"
LINE 4: INNER JOIN "Rockefeller_ApplicationDb".public.userro..
Run Code Online (Sandbox Code Playgroud)
SQL存储功能
SELECT Department.nDeptID
FROM Users INNER JOIN Permission
ON Users.nUserID = Permission.nUserID INNER JOIN UserRoleMapping
ON Users.nUserID = UserRoleMapping.nUserID INNER JOIN Department
ON Permission.nDeptInst = Department.nInstID
AND Department.nInstID = 60
WHERE
Users.nUserID = 3;
Run Code Online (Sandbox Code Playgroud)
PostgreSQL存储函数
SELECT dep.ndept_id
FROM "Rockefeller_SecurityDb".public.users as u
INNER JOIN "Rockefeller_SecurityDb".public.permissions p ON u.nuser_id = p.nuser_id
INNER JOIN "Rockefeller_ApplicationDb".public.userrolemapping as urm ON u.nuser_id = urm.nuser_id
INNER JOIN "Rockefeller_ApplicationDb".public.department dep ON …
Run Code Online (Sandbox Code Playgroud) 有没有办法查看 Postgres 表具有什么样的副本标识,无论是使用 pgAdmin 还是通过查询?
postgresql ×7
pgadmin-4 ×2
python ×2
backup ×1
combinators ×1
definition ×1
inner-join ×1
mysql ×1
nestjs ×1
pg-restore ×1
pgadmin ×1
plpgsql ×1
sql ×1
sql-server ×1
sqlalchemy ×1
theory ×1
transactions ×1
typeorm ×1