我需要向我们的 postgresql 服务器添加新的语言环境(x86_64-unknown-linux-gnu 上的 PostgreSQL 9.4.4,由 gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2,64 位编译)。\n因为语言环境不是还安装在 Ubuntu 上,我添加了它们
\n\nsudo locale-gen fr_FR.UTF-8
语言环境现在确实显示为
\n\nlocale -a
我重新启动了 postgresql 服务器,但区域设置在 postgresql 中不可见。我找不到select * from pg_collation;
当我尝试使用 手动创建排序规则时create collation fr_FR (LOCALE=\xe2\x80\x98fr_FR.utf8\xe2\x80\x99),出现此错误
ERROR: could not create locale "\xe2\x80\x98tr_tr.utf8\xe2\x80\x99": Success
我是不是少了一步?
\n目前我有下表:
CREATE TABLE demo (
id SERIAL PRIMARY KEY,
key TEXT NOT NULL,
other_key TEXT NOT NULL,
quantity BIGINT NOT NULL,
date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()
);
Run Code Online (Sandbox Code Playgroud)
现在我想按这样的查询进行分组:
SELECT other_key, SUM(quantity) FROM demo GROUP BY other_key;
Run Code Online (Sandbox Code Playgroud)
到目前为止,效果很好,但是现在我想按键过滤并打印date表的最新信息,有什么好的方法吗?
伪(将失败,因为密钥不在分组依据中)
SELECT other_key, SUM(quantity), MAX(date) FROM demo GROUP BY other_key WHERE key = ?;
Run Code Online (Sandbox Code Playgroud)
我最初的想法是子查询:
SELECT other_key, SUM(quantity), MAX(date) FROM (SELECT * FROM demo WHERE key = ?) GROUP BY other_key;
Run Code Online (Sandbox Code Playgroud)
有更好的方法吗?那么什么是该表的良好索引呢?
我当前的索引是:
CREATE INDEX demo_all_idx ON …Run Code Online (Sandbox Code Playgroud) 我刚刚注意到 PostgreSQL 允许在数据库中重复外键(以及可能的其他约束)名称,只要它们位于不同的表上即可。
因此,如果父表是并且Foo它有两个子表,则两个表上的外键都可以命名。BarXBarYFK_fooid
在我看来,这是一个糟糕的设计,因为
select * from information_schema.referential_constraints
where constraint_name = 'FK_fooid'
Run Code Online (Sandbox Code Playgroud)
将返回两行相同的行,无法区分哪一行对应于哪个表/键。
有没有办法在 Postgres 中的数据库中禁用约束名称的重复,并强制每个约束都有唯一的名称?
我正在尝试通过 Postgres 中 jsonb 字段上的属性将普通表连接到具有 jsonb 字段的表。例子:
普通表:
create table Res
(
id uuid default uuid_generate_v4() not null
constraint res_pkey
primary key
)
;
Run Code Online (Sandbox Code Playgroud)
带有 jsonb 的表:
create table res_rem_sent
(
body jsonb not null,
search tsvector,
created_at timestamp with time zone default now(),
id uuid default uuid_generate_v4() not null
constraint res_rem_sent_pkey
primary key
);
create index idx_res_rem_sent
on res_rem_sent (body)
;
create index idx_search_res_rem_sent
on res_rem_sent (search)
;
Run Code Online (Sandbox Code Playgroud)
该body字段可能如下所示:{"resId": <GUID>, ....}
我想将res表连接到id等于给定 GUID id …
我正在使用一个jsonb列,其中 JSON 文档包含大整数 (PostgreSQL 9.5)。我注意到,当存储的值有太多有效数字时,它会被截断。
作为示例,我将其插入到我的表中:
{"value": 7598786232076607106}
Run Code Online (Sandbox Code Playgroud)
当我选择返回同一行时,我得到:
{"value": 7598786232076607000}
Run Code Online (Sandbox Code Playgroud)
根据文档numeric,jsonb 中的数字字段使用postgres 的标准类型存储,并且numeric通常允许:
小数点前最多 131072 位;小数点后最多 16383 位
jsonb是否有可能通过, 而不是截断来真正获得这种行为?
我无法在 PostgreSQL 中编写正常的选择过程。我在 SQL Server 方面有很好的经验。但 Postgres 看起来完全是一个不同的星球。
有人能帮我如何在 Postgres 中写这个语句吗?
create proc procedurename @somedate date
begin
select * from sometable where date>= @somedate
end
Run Code Online (Sandbox Code Playgroud)
我可以像这样执行它
exec procedurename 2017-05-02
Run Code Online (Sandbox Code Playgroud)
我尝试编写一个存储过程,它返回一个带有类似内容的表
Create or replace function hrms.salary() returns table(
lastmodified timestamp without time zone ,
employeeid integer ,
insuranceno character varying ,
uanno character varying ,
basic integer ,
hra numeric ,
conveyence integer ,
fixedallowance integer ,
epf numeric ,
eps numeric ,
esic numeric ,
bankname character varying ,
ifsccode …Run Code Online (Sandbox Code Playgroud) 我有一张Policies桌子。
现在我需要在10 月份获得所有待处理Policies的 a和所有已发出的a 。pendDateOctoberPoliciesissueDate
我在用着postgreSQL 9.6。这些日期可以为空,所以我不能使用简单的AND. 那个月我只需要 和pending,issued所以 OR 不起作用。
我解决了两个查询,但现在正在添加更多状态,我想以某种方式进行整合。可能的?
我创建了一个带有大写字母的架构,如下所示:
CREATE SCHEMA "requeteSQL" AUTHORIZATION ......;
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试GRANT一些特权时,例如:
GRANT SELECT ON ALL TABLES IN SCHEMA requetesql TO ....;
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Run Code Online (Sandbox Code Playgroud)ERROR: schema "requetesql" does not exist
我意识到我需要更新查询,但如果我有一个包含camelCase空格的数据库,则必须在标识符上使用双引号(即架构、表、列)。我如何摆脱考虑到我的标识符中不能有大写字母或空格。我需要将它们全部标准化为Snake_case。