这是我正在尝试做的一个例子,
SELECT *
FROM ( VALUES ('{"a":1}'::json) )
AS t(data)
WHERE data = '{"a":1}'::json;
Run Code Online (Sandbox Code Playgroud)
但它给了我这个错误,
ERROR: operator does not exist: json = json
LINE 4: WHERE data = '{"a":1}'::json;
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Run Code Online (Sandbox Code Playgroud) 你能解释一下,我如何优化这样的选择:
SELECT * FROM calls WHERE id_temp % 5 = 0 LIMIT 300000
Run Code Online (Sandbox Code Playgroud)
此选择正在处理具有 5000 万条记录的表。
非常感谢,祝你有美好的一天。
这是在PostgreSQL中创建新表的方法,
CREATE TABLE foo (
foo_id int PRIMARY KEY,
bar text,
);
Run Code Online (Sandbox Code Playgroud)
如果需要检查该表是否已存在并CREATE仅在未找到时继续处理,我该如何执行此操作?
使用以下查询时,我无法从 bnrcno 列中获取数据。
select 'insert into table values('||id||','||bnrcno||','||chargetype||','||domno||','||coa_id||','||liability_gl||','||revenue_gl||','||taxno||')'
from bill_charges_map where domno=5
Run Code Online (Sandbox Code Playgroud)
该brcno列是整数类型,其中的大多数值都为空。
我只使用 PostgreSQL,我这辈子再也不会切换数据库软件了,所以我不在乎与一些理论上的“SQL 标准”兼容,这些标准实际上并不存在。
我喜欢“模式”的想法,我很清楚它们是什么,但让我烦恼的一件事是你不能嵌套它们。因此,您只能有一个“类别”,任何“子类别”都必须是表名的一部分。
为什么不支持嵌套模式?既然“模式”无论如何都不在 SQL 标准中,为什么它们不完全采用并允许嵌套模式?
当然,我还没有真正需要它,但它在理论上和各种复杂情况下似乎很有用。
我想使用COPYPostgres 中的函数将数据发送到 .csv 文件。但我使用匿名块,所以我的表名应该是变量的值。
COPY (SELECT cname.portal from user) To '/tmp/out.csv' With CSV;
Run Code Online (Sandbox Code Playgroud)
cname我的匿名块内的变量在哪里。我尝试使用EXECUTE格式,但它也不起作用。我试过类似的东西:
EXECUTE format (' COPY (select * from %s.portal,cname ) To '/tmp/out1.csv' With CSV');
Run Code Online (Sandbox Code Playgroud) 免责声明:我将 PostgreSQL 和 PostgreSQL 单独用于我的所有数据库。这不是某种“仇恨”。
这是困扰我多年的事情,但在这一点上,在2020年,它只是荒谬的。
来源:https : //www.postgresql.org/docs/current/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHAT
application_name 可以是任何少于 NAMEDATALEN 字符(标准版本中为 64 个字符)的字符串。它通常由应用程序在连接到服务器时设置。该名称将显示在 pg_stat_activity 视图中并包含在 CSV 日志条目中。它也可以通过 log_line_prefix 参数包含在常规日志条目中。在 application_name 值中只能使用可打印的 ASCII 字符。其他字符将替换为问号 (?)。
(强调我的。)
所以,自称“世界上最先进的开源关系数据库”不支持 Unicode/UTF-8 这个特定的东西,但在其他地方。它迫使我(和我的潜在老板,如果我有的话)看到一堆“???????????” 遍布控制面板,例如在 pgAdmin 4 中。
我听说这应该是出于“安全问题”的考虑。在他们设置“Unicode 引擎”之前的某个阶段设置了有关 application_name 的某些内容或类似的内容。我不明白。如果真的是这样,当然,力ASCII-只为应用程序名称时,它在最初的连接设置,但也允许使用Unicode / UTF-8后当设置应用程序名称,连接已经建立后使用,在正常查询“SET”关键字!
我不明白。为什么我被迫到处看到这些丑陋的问号,只是因为我的语言恰好包含的不仅仅是 A-Za-z?即使以英语为中心的数据库也可能有与其他语言相关的脚本或具有花哨名称的服务,因此即使 PG 项目以美国为中心,这仍然不能成为借口。
PostgeSQL 有一些非常丰富的字段和行大小限制(分别为 1GB 和 1.6TB)。
另一方面,Sybase ASE 的行大小限制在 4 或 8KB 左右。
例如,在 Sybase ASE 15.7 上我看到:
sqldev.mydatabase.1> create table foo2(a VARCHAR(7000));
Warning: Row size (7034 bytes) could exceed row size limit, which is 1962 bytes
Run Code Online (Sandbox Code Playgroud)
这不仅仅是关于性能的警告,因为当我尝试插入大于 1962 字节的内容时,它实际上是强制执行的:
Attempt to update or insert row failed because resultant row of size 4462 bytes is larger than the maximum size (1962 bytes) allowed for this table.
Command has been aborted.
Run Code Online (Sandbox Code Playgroud)
我猜由于共同的传统,类似的限制适用于 SQL Server,谷歌似乎同意(但我没有在 SQL Server 上尝试过)。
我假设这种巨大的差异一定是一些截然不同的架构决策或一些基本权衡的结果,这些权衡是由每个 RDBMS 以不同方式决定的。如果这是正确的,那将是什么权衡或架构决策?
我想在 bigint 类型的列之一中找出负值。所以当我选择 *from tablename where columname(bigint) <0 ...它给我一个错误。
SQL Error [42883]: ERROR: operator does not exist: bigint[] < integer
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Position: 60
ERROR: operator does not exist: bigint[] < integer
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Position: 60
Run Code Online (Sandbox Code Playgroud)
表定义为:
CREATE TABLE oper.asset_input_event
(
id bigserial NOT NULL,
trip_ids bigint[],
cassandra_uuid …Run Code Online (Sandbox Code Playgroud) postgresql ×12
dynamic-sql ×2
copy ×1
datatypes ×1
insert ×1
jobs ×1
json ×1
performance ×1
plpgsql ×1
schema ×1
sequence ×1
spatial ×1
sql-server ×1
sybase-ase ×1
table ×1