AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-153964

Ron Piggott's questions

Martin Hope
Ron Piggott
Asked: 2024-02-02 10:36:55 +0800 CST

没有唯一序列约束的 PostgreSQL 表

  • 5

我使用 PostgreSQL。是否有一个查询来获取对序列列没有唯一约束的所有表的列表?如果它有助于形成查询,我将“引用”用于我的序列列。

这是包含 this.das 的表的示例

\d+ a_practical_approach_when_there_is_a_lot_to_do
                                                                   Table "public.a_practical_approach_when_there_is_a_lot_to_do"
        Column        |           Type           | Collation | Nullable |                                      Default                                      | Storage  | Stats target | Description
----------------------+--------------------------+-----------+----------+-----------------------------------------------------------------------------------+----------+--------------+-------------
 reference            | bigint                   |           | not null | nextval('a_practical_approach_when_there_is_a_lot_to_do_reference_seq'::regclass) | plain    |              |
 display_order        | bigint                   |           |          |                                                                                   | plain    |              |
 principal            | text                     |           |          |                                                                                   | extended |              |
 explanation          | text                     |           |          |                                                                                   | extended |              |
 add_date             | timestamp with time zone |           |          |                                                                                   | plain    |              | UTC
 membership_reference | bigint                   |           |          |                                                                                   | plain    |              |
Indexes:
    "a_practical_approach_when_there_is_a_lot_to_do_reference_unique" UNIQUE CONSTRAINT, btree (reference)
Access method: heap
postgresql
  • 1 个回答
  • 10 Views
Martin Hope
Ron Piggott
Asked: 2022-10-14 06:31:32 +0800 CST

PostgreSQL INSERT 多维数组

  • 5

我花了几个小时查看 PostgreSQL INSERT 数组文档和示例。但我只是越来越困惑。

我创建了word_mash_word_cube_definitionscolumndefinition为 type的表text[]。

当我创建我使用的列时text[][]。但\d+显示为text[].

在 PHP 中,数组是:

$design[1] = [ 'letter' => null , 'direction' => 'down' , 'x-axis' => 7 , 'y-axis' => 3 ];
$design[2] = [ 'letter' => null , 'direction' => 'left' , 'x-axis' => 7 , 'y-axis' => 4 ];
$design[3] = [ 'letter' => null , 'direction' => 'up' , 'x-axis' => 6 , 'y-axis' => 4 ];
$design[4] = [ 'letter' => null , 'direction' => 'left' , 'x-axis' => 6 , 'y-axis' => 3 ];
$design[5] = [ 'letter' => null , 'direction' => 'down' , 'x-axis' => 5 , 'y-axis' => 3 ];
$design[6] = [ 'letter' => null , 'direction' => 'down' , 'x-axis' => 5 , 'y-axis' => 4 ];

我的目标是将整个数组存储在 1 行中。但我不知道这是否可能。

有人可以告诉我正确的吗

INSERT INTO word_mash_word_cube_definitions ( definition ) VALUE ( ??? )

我搞不清楚了。

postgresql
  • 1 个回答
  • 32 Views
Martin Hope
Ron Piggott
Asked: 2022-03-27 17:56:12 +0800 CST

选择给定数组中包含字母数组的行

  • 2

text[]我想在“拼写”( ) 栏中 搜索字母: annoyt

我需要它来查找单词:any , annoy , no , an , toy 但找不到: annoy 的派生词(烦恼,烦恼),只找到一次。

如果甚至缺少一个字母(例如anoyt),我还需要查询 NOT find annoy 。

我正在使用 PostgreSQL 13.5

ronshome=# SELECT reference, word, spelling FROM word_mash_dictionary
           WHERE word LIKE 'annoy';
 reference | word  |  spelling
-----------+-------+-------------
       420 | annoy | {a,n,n,o,y}
(1 row)

这是表结构:

                                                      Table "public.word_mash_dictionary"
   Column    |  Type  | Collation | Nullable |                         Default                         | Storage  | Stats target | Description
-------------+--------+-----------+----------+---------------------------------------------------------+----------+--------------+-------------
 reference   | bigint |           | not null | nextval('word_mash_dictionary_reference_seq'::regclass) | plain    |              |
 word        | text   |           |          |                                                         | extended |              |
 spelling    | text[] |           |          |                                                         | extended |              |
 ignore      | bigint |           |          |                                                         | plain    |              |
 list_100    | bigint |           |          |                                                         | plain    |              |
 list_300    | bigint |           |          |                                                         | plain    |              |
 list_500    | bigint |           |          |                                                         | plain    |              |
 list_800    | bigint |           |          |                                                         | plain    |              |
 list_1000   | bigint |           |          |                                                         | plain    |              |
 list_2000   | bigint |           |          |                                                         | plain    |              |
 list_3000   | bigint |           |          |                                                         | plain    |              |
 list_5000   | bigint |           |          |                                                         | plain    |              |
 list_7000   | bigint |           |          |                                                         | plain    |              |
 list_10000  | bigint |           |          |                                                         | plain    |              |
 word_length | bigint |           |          |                                                         | plain    |              |
postgresql select
  • 1 个回答
  • 106 Views
Martin Hope
Ron Piggott
Asked: 2021-12-16 23:01:31 +0800 CST

从月份和日期中删除前导零

  • 0

PostgreSQL 聊天室中的某个人给了我这个语法。它用于VIEW输出 RSS 提要链接的 a:

to_char(tips_chronic_pain_weekly_selection.start_date, 'YYYY/MM/DD'::text)
Example output: 2021/09/13

我不熟悉这是如何工作的。我可以删除月份和日期的前导0吗?这是几个月前给我的,作为以下的缩短版本:

concat( extract( YEAR FROM tips_physical_disability_weekly_selection.start_date), '/',  extract( MONTH FROM tips_physical_disability_weekly_selection.start_date), '/',  extract( DAY FROM tips_physical_disability_weekly_selection.start_date) )
postgresql date-format
  • 1 个回答
  • 1270 Views
Martin Hope
Ron Piggott
Asked: 2021-12-16 14:28:39 +0800 CST

什么 PostgreSQL 查询将返回未使用的序列号?

  • -2

我启用了一个 UNIQUE 键,因此 PostgreSQL 将作为一组 INSERT INTO 语句的重复条目的校对器。现在我需要一个未使用的 SEQUENCE 数字的列表,所以接下来我会填充这些数字。

postgresql auto-increment
  • 1 个回答
  • 48 Views
Martin Hope
Ron Piggott
Asked: 2021-12-09 22:36:58 +0800 CST

MariaDB 理解“事件”间隔

  • 0

我创建了我的第一个活动:

ALTER EVENT flush_logs_event 
ON SCHEDULE EVERY 6 HOUR 
COMMENT 'Rotate /var/log/mysql/master-bin*' 
DO FLUSH LOGS;

我将它从“12”更改为“6”,因为日志复制的增长速度有多快。我希望它按时间而不是文件大小旋转,以使我更轻松地部署其他从站。

我认为“6 小时”是指 6H00 12H00 18H00 和 24H00。同时我改变了事件我也对/etc/mysql/my.cnf进行了调整:

expire_logs_days=7

然后我做了

systemctl restart mariadb.service

当 MariaDB 重新启动时,master-bin 旋转。它创建了master-bin.000006。当我重新启动 MariaDB 时,大约是 5:21。这是否意味着 master-bin 将在 11:21、17:21 等旋转?

为了全面披露,我还包括:

MariaDB [mysql]> show events \G
*************************** 1. row ***************************
                  Db: mysql
                Name: flush_logs_event
             Definer: root@localhost
           Time zone: SYSTEM
                Type: RECURRING
          Execute at: NULL
      Interval value: 6
      Interval field: HOUR
              Starts: 2021-12-09 05:21:23
                Ends: NULL
              Status: ENABLED
          Originator: 1
character_set_client: utf8mb4
collation_connection: utf8mb4_general_ci
  Database Collation: utf8mb4_general_ci

谢谢。

mariadb log
  • 1 个回答
  • 28 Views
Martin Hope
Ron Piggott
Asked: 2019-07-25 20:29:56 +0800 CST

Postgresql日期函数以可读格式返回范围

  • 0

我想知道是否可以使用 postgresql 的 date-time 、 concat 和 case 函数来给出以下结果之一:

  • 2019 年 6 月 4 日至 11 日(第 1 天和第 2 天在同一个月内)
  • 2019 年 7 月 27 日至 7 月 3 日(第 1 天和第 2 天在不同的日历月,但在同一日历年)
  • 2019 年 12 月 29 日至 2020 年 1 月 4 日(其中第 1 天和第 2 天在不同的日历月和不同的年份)

我打算创建一个视图,用于在每周提示更改时发布状态更新(例如到 Twitter)。在我的编程中,我尽量使用数据库的原生函数。在一个理想的世界里,我不会使用源代码来完成这个,前提是 postgresql 本身能够做到这一点。

到目前为止,我创建的 VIEW 的 SELECT 查询是:

SELECT 'chronic pain'::text AS section,
    'https://rons-home.net/en/living-life-lab/tips/living-with-chronic-pain'::text AS link,
    tips_chronic_pain.reference,
    tips_chronic_pain.tip,
    tips_chronic_pain_weekly_selection.start_date,
    tips_chronic_pain_weekly_selection.end_date
FROM tips_chronic_pain
JOIN tips_chronic_pain_weekly_selection ON tips_chronic_pain.reference = tips_chronic_pain_weekly_selection.tips_chronic_pain_reference
ORDER BY tips_chronic_pain_weekly_selection.start_date DESC
LIMIT 1

我创建了以下 2 个表:

表 #1 包含所有提示:

CREATE TABLE public.tips_chronic_pain
(
  reference bigint NOT NULL DEFAULT nextval('tips_chronic_pain_reference_seq'::regclass),
  tip text,
  add_date timestamp with time zone DEFAULT now(), -- UTC
  membership_reference bigint,
  CONSTRAINT tips_chronic_pain_pkey PRIMARY KEY (reference)
)

表 #2 确定当前正在显示哪个提示:

CREATE TABLE public.tips_chronic_pain_weekly_selection
(
  reference bigint NOT NULL DEFAULT nextval('tips_chronic_pain_weekly_selection_reference_seq'::regclass),
  tips_chronic_pain_reference bigint,
  start_date timestamp with time zone DEFAULT now(), -- UTC
  end_date timestamp with time zone DEFAULT now(), -- UTC
  CONSTRAINT tips_chronic_pain_weekly_selection_pkey PRIMARY KEY (reference)
)
  • 列tips_chronic_pain_weekly_selection.start_date 提供第一个日期
  • 列tips_chronic_pain_weekly_selection.end_date 提供第二个日期
postgresql case
  • 1 个回答
  • 29 Views
Martin Hope
Ron Piggott
Asked: 2019-05-22 07:18:16 +0800 CST

pgsql 返回以整个单词结尾的部分文本字段

  • 1

我发现这个 PHP 代码返回一个以整个单词结尾的子字符串(IE 以空格分隔):

if ( strlen( $body ) < $maxlength ) return $body;
$body = substr( $body , 0 , $maxlength );
$rpos = strrpos( $body , ' ' );
if ( $rpos > 0 ) $body = substr( $body , 0 , $rpos );
return $body;

是否有可能使用 pgsql 的字符串操作函数获得相同的结果?

postgresql string-manipulation
  • 1 个回答
  • 22 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve