这是关于数据库管理员的一般问题。
DB 中字段的字符限制是否有某种标准化?在数据库端为姓名、电话号码等指定字符限制是有意义的,您知道输入的数据类型,并且您希望输入的数据合理,因此您可以限制字符限制。但是你怎么知道在这个疯狂的世界里什么是合理的限制,可能会有很多例外。
就我而言,它是英国本地公司的系统,只有 10-15 名员工。因此,如果需要,我可以返回并更改它,但我宁愿输入一个合理的限制来开始。
对不起,如果这个问题已经被问到了。如果有,我无法通过 Google 或类似问题找到它。
我有一个可以包含相当大的BYTEA值的表(同样适用于大TEXT值)。它看起来像这样:
CREATE TABLE testtable (
id SERIAL PRIMARY KEY,
name TEXT UNIQUE NOT NULL, -- This is just an example: this could be the PK
value BYTEA -- This could be TEXT
);
Run Code Online (Sandbox Code Playgroud)
如果使用此表的应用程序尝试使用相同的 插入两行name,我会在日志中收到此错误(当然,这是预期错误):
CREATE TABLE testtable (
id SERIAL PRIMARY KEY,
name TEXT UNIQUE NOT NULL, -- This is just an example: this could be the PK
value BYTEA -- This could be TEXT
);
Run Code Online (Sandbox Code Playgroud)
虽然记录错误以及记录语句(在此特定上下文中可能还有“name”的值)很有用,但记录 longBYTEA或TEXTvalue 不是。事实上,日志中的二进制数据以文本形式(例如 …
我需要提供自定义的停用词列表。从字典手册部分来看,执行此操作的方法是将一个停用词文件放入$SHAREDIR/tsearch_data/.
使用AWS时可以这样做吗?如果不是,是否可以通过命令行提供停用词文件?
我有一个表,其中一个字段是 JSON 数组。我需要将接收到的 JSON 数组附加到该字段中而不覆盖现有值。
类似的东西:
CREATE OR REPLACE FUNCTION add_array(
array_received json[])
RETURNS void AS
$BODY$
update table set _array_field = _array_field | array_received ...;
$BODY$
LANGUAGE plpgsql VOLATILE;
Run Code Online (Sandbox Code Playgroud) 我的机器上安装了 PostgreSQL 9.5 版(Windows 7 Enterprise x64 位版本)。我在模式“public”中有几个数据库。我想使用 LAN 连接从另一台机器(Windows 7)使用/访问这些数据库中的一个(以便该数据库可以作为两台机器之间的共享数据库)。我想知道是否可以通过 postgresql.conf 对话窗口中的“listen_addresses”选项来完成?如果没有,有没有其他方法可以做到这一点?
我似乎无法使用我的数据库在 Windows 上转储/恢复。使用的行和错误消息:
pg_dump -h localhost -U postgres --format=c -O -d ue > latest.dump
pg_restore -h localhost -U postgres -d ue latest.dump
Run Code Online (Sandbox Code Playgroud)
得到这个错误,
pg_restore: [archiver] 输入文件似乎不是有效的存档
有了这个,
pg_dump -h localhost -U postgres -O -d ue > latest.dump
psql -h localhost -U postgres -d ue -f latest.dump
Run Code Online (Sandbox Code Playgroud)
我收到这个错误,
psql:latest.dump:1: 错误:编码“UTF8”的字节序列无效:0xff
我完全被难住了。大多数搜索结果与不使用正确的pg_restore/psql与导出的文件类型有关pg_dump,但正如您在上面看到的,我已经考虑了这一点。
latest.dump 似乎正确填写,至少以纯格式导出我可以阅读的 SQL 并且是数据库的正确导出。
运行下面的命令,我得到“返回“记录”的函数需要一个列定义列表。
SELECT *
FROM json_to_record('{"a":1,"b":2,"c":3,"d":4}');
ERROR: a column definition list is required for functions returning "record"
LINE 1: SELECT * FROM json_to_record('{"a":1,"b":2,"c":3,"d":4}');
Run Code Online (Sandbox Code Playgroud)
没关系。我知道它想要什么。
SELECT *
FROM json_to_record('{"a":1,"b":2,"c":3,"d":4}')
AS (a int, b int, c int, d int);
Run Code Online (Sandbox Code Playgroud)
此外,在 PostgreSQL 中,所有表都已经有一个以相同名称创建的类型。
CREATE TABLE foo(a,b,c,d)
AS VALUES
(1,2,3,4);
Run Code Online (Sandbox Code Playgroud)
这将创建一个foo链接到新创建的 table的内部类型foo。不过,我可以很容易地创建一个类似的类型bar。
CREATE TYPE bar AS (a int, b int, c int, d int);
Run Code Online (Sandbox Code Playgroud)
能够将返回的记录转换json_to_record()为 bar会很棒。
SELECT *
FROM json_to_record('{"a":1,"b":2,"c":3,"d":4}')
AS foo; -- bar? anything? …Run Code Online (Sandbox Code Playgroud) 为什么这如此棘手,令牌设置为什么,它不等于 null 也不等于空字符串?
SELECT lexemes
FROM ts_debug('This is a title')
WHERE alias = 'asciiword';
lexemes
---------
{}
{}
{}
{titl}
(4 rows)
Run Code Online (Sandbox Code Playgroud)
好吧..所以我想摆脱{},
SELECT lexemes
FROM ts_debug('This is a title')
WHERE alias = 'asciiword'
AND lexemes <> '{}'
AND lexemes <> ARRAY[]::text[]
AND lexemes IS NOT NULL
AND lexemes <> ARRAY[' ']
AND lexemes <> ARRAY[null]::text[];
Run Code Online (Sandbox Code Playgroud)
我知道其中大多数都行不通。,但我完全困惑为什么<> '{}'不起作用<> ARRAY[]::text;。我该如何过滤掉这个?
我有一个存储父/子记录的表,如下所示:
+-------+------------+---------+---------+------------+-----------+
|custid | custname | deptid | company |parentcustid| enrolled |
+=======+============+=========+=========+============+===========+
| 7060 | Sally | AB1 | comp1 | null | 1 |
| 6953 | Ajit | AB7 | comp2 | 7060 | 1 |
| 6957 | Rahul | DE1 | comp3 | 7060 | 1 |
| 6958 | uday | TG6 | comp4 | 7060 | 1 |
| 6959 | john | HY7 | comp5 | 7060 | 1 |
| 6960 …Run Code Online (Sandbox Code Playgroud) 假设我在 Postgres 中有一个具有此值的文本字段:
'bar$foo$john$doe$xxx'
Run Code Online (Sandbox Code Playgroud)
我想将最后一次出现的美元 ( $) 字符替换为另一个字符,例如“-”。替换后该字段的内容应为:
'bar$foo$john$doe-xxx'
Run Code Online (Sandbox Code Playgroud) postgresql ×8
array ×2
datatypes ×2
amazon-rds ×1
bytea ×1
condition ×1
hierarchy ×1
join ×1
json ×1
log ×1
null ×1
pg-dump ×1
pg-hba.conf ×1
pg-restore ×1
remote ×1
replace ×1
row ×1
sql-server ×1
windows ×1