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
    • 最新
    • 标签
主页 / dba / 问题

问题[redshift](dba)

Martin Hope
Andrew Wei
Asked: 2023-01-31 12:45:27 +0800 CST

如何为非空对象查询 redshift SUPER

  • 5

语境:

我有一个名为的列event_properties,其中有很多值{}是 redshift SUPER 数据类型。许多值都是空对象,例如:

空事件属性

客观的:

过滤掉不是“空对象”的值

我试过的:

  • 转换为 ::text,将导致空值
  • SUPER 类型不len支持 (length) 函数

我想要完成的事情:

(下面的查询不起作用,但应该证明我正在努力完成)

select event_properties from native_app_events where event_properties::text != '{}'
select event_properties from native_app_events where len(event_properties) > 5
redshift
  • 1 个回答
  • 14 Views
Martin Hope
Kit Sunde
Asked: 2022-07-28 22:33:05 +0800 CST

是否可以删除 RedShift 自动物化视图?

  • 0

我正在尝试更改表定义,但它依赖于由 RedShift Auto Materialization 而不是我们管理的物化视图。所以尝试

ALTER TABLE my_table
    ALTER COLUMN my_column TYPE VARCHAR(100);

错误

[0A000] 错误:无法更改实体化视图使用的列的类型

所以我尝试放弃物化视图

DROP MATERIALIZED VIEW pg_automv.auto_mv_53022635;

这给出了一个权限错误

[42501] 错误:架构 pg_automv 的权限被拒绝

redshift
  • 1 个回答
  • 131 Views
Martin Hope
Eyal leshem
Asked: 2022-02-25 08:18:55 +0800 CST

pg_catalog 是否可用于 aws redshift 数据共享使用者

  • 0

我刚开始阅读有关 aws redshift数据共享功能的信息。我想知道数据消费者是否可以访问向他们公开的表的“pg_catalog”/INFOMATION_SCHEMA?

(目标是数据消费者将能够按表名获取列列表)

redshift
  • 1 个回答
  • 64 Views
Martin Hope
GeoSal
Asked: 2021-06-17 14:34:03 +0800 CST

Redshift - 将数据插入临时表,条件为列 doc_id 应该是唯一的,而不是 null

  • 1

我正在尝试在 Redshift 中创建一个临时表并将数据插入其中。我的目标是为唯一的doc_id WHERE doc_id IS NOT NULL创建一条记录。

这是我的代码:

-- Creating temp table to load only rows with unique and not null doc_id
DROP TABLE IF EXISTS TMP_table CASCADE;

CREATE TEMP TABLE IF NOT EXISTS TMP_table
(
    uuid varchar,
    id integer,
    doc_id integer,
    revenue double,
    doc_date varchar,
);

-- insert into the temp table and add the distinct and not null filter on the doc_id
INSERT INTO TMP_table
(
    uuid,
    id,
    doc_id,
    revenue,
    doc_date
)
SELECT
    uuid,
    id,
    select DISTINCT (table_x.doc_id) from table_x where table_x.doc_id IS NOT NULL,
    revenue,
    doc_date
FROM schema.table_x;

运行上面的代码后,我得到一个语法错误几乎不同。而且我似乎无法弄清楚错误是什么。

请问有什么指导吗?

redshift
  • 1 个回答
  • 451 Views
Martin Hope
James
Asked: 2021-03-23 21:21:07 +0800 CST

基于开始/结束日期名册的活跃用户月度摘要

  • 0

我有一张表格,说明谁参与了一个项目,从开始日期到结束日期。我需要一些帮助来编写一个查询,该查询将自今年年初以来在每个月底返回“活跃”用户的数量。

DROP TABLE "public"."roster";
CREATE TABLE "public"."roster" ("id" int,"user_id" int,"project_id" int,"start_date" datetime,"end_date" datetime,"closed_date" datetime, PRIMARY KEY ("id"));

INSERT INTO "public"."roster" ("id", "user_id", "project_id", "start_date", "end_date", "closed_date") VALUES
(1, 1, 1, '2019-05-27 00:00:00', '2021-01-15 00:00:00', NULL);

INSERT INTO "public"."roster" ("id", "user_id", "project_id", "start_date", "end_date", "closed_date") VALUES
(2, 2, 2, '2020-05-27 00:00:00', '2021-02-01 00:00:00', '2021-02-05 00:00:00');

INSERT INTO "public"."roster" ("id", "user_id", "project_id", "start_date", "end_date", "closed_date") VALUES
(3, 3, 3, '2020-05-27 00:00:00', '2024-02-01 00:00:00', '2021-02-05 00:00:00');

INSERT INTO "public"."roster" ("id", "user_id", "project_id", "start_date", "end_date", "closed_date") VALUES
(4, 4, 4, '2020-05-27 00:00:00', '2021-03-05 00:00:00', NULL);
id  user_id project_id  start_date            end_date              closed_date
1   1       1           2019-05-27 00:00:00   2021-01-15 00:00:00   NULL
2   2       2           2020-05-27 00:00:00   2021-02-01 00:00:00   2020-02-05 00:00:00
3   3       3           2020-05-27 00:00:00   2024-02-01 00:00:00   2020-02-05 00:00:00
4   4       4           2020-05-27 00:00:00   2021-03-05 00:00:00   NULL

结果将显示每个月有多少不同的用户有一个活跃的项目(仅自今年年初以来)。

所以对于上面的数据集,我们可以看到所有 4 个项目在 2021 年 1 月月份都是“活跃的”,因为结束日期在未来。

2021-01-31 | 3 (4 projects were active in some way, during January)
2021-02-28 | 2 (3 projects were active in some way, during February)
2021-03-31 | 1 (1 project was active in some way, during March)

最后一点复杂性是,有时项目可以在 EndDate 之前关闭,我想排除任何 endDate 在未来但项目实际上已经关闭的用户。

例如,在上面的数据集中,第三个项目的结束日期为 2024 年 2 月,但该项目于 2021 年 2 月结束。所以从技术上讲,这个人在 2021 年 1 月和 2 月是活跃的,但不是 2021 年 3 月及以后。

ps 希望得到 Redshift 的答案

redshift
  • 1 个回答
  • 106 Views
Martin Hope
Tpk43
Asked: 2021-02-24 11:49:45 +0800 CST

在 redshift 动态 SQL 中包含单引号字符串

  • 0

我有函数命名

Schema.func_date(date,varchar)

我想这样做(我在 Store proc 中使用以下语句)

Execute 'Select *, ID as Main_Id, ' ||
         'schema.func_date(quote_literal('2020-02-20'),quote_literal('ST')), '||
         'from main_table'

传递单引号字符串时出现无效操作错误。如何在执行语句中完美传递单引号字符串?

redshift dynamic-sql
  • 1 个回答
  • 1583 Views
Martin Hope
Jahziel Rae Arceo
Asked: 2021-02-10 16:29:59 +0800 CST

在 SIMILAR TO 中使用插入符号 (^) 进行模式列表匹配否定,在 Redshift 中使用 ~ 查询

  • 0

我对在 Redshift 中使用 POSIX 正则表达式很陌生。老实说,我认为这种模式必须兼容。

[^A-Za-z0-9\\.\\,-]+

但是,正如我尝试过这样的查询

SELECT * FROM my_table WHERE string_column ~ '[^A-Za-z0-9\\.\\,-]+';

它给了我一个与我喜欢的不匹配的结果,并且似乎将插入符号视为字符文字。我也试过用[^[:alnum:]]没用。发生这种情况的原因可能是什么?我是否输入了错误,或者这是 Redshift 或 JDBC 驱动程序中的限制?

我目前正在通过 JetBrains DataGrip(最新版本)运行查询,并使用最新的 Amazon Redshift JDBC 驱动程序运行它。

redshift regex
  • 1 个回答
  • 152 Views
Martin Hope
checkpoint
Asked: 2020-12-12 04:20:21 +0800 CST

如何使用 SQL CASE 结果比较一列并获得另一个案例结果

  • 0

我正在尝试将我的案例结果(desirecountry)与现有列(so.country_name)进行比较,以获得另一个案例结果(Final_Country_Map_Name):

     SELECT subs."user email", subs."user join date", subs.location,
                iso.country_name as iso_country, iso.country_id as iso_country_id, 
                    users.country, users.event_type,
    -- 1.  
    CASE  WHEN subs.location = iso.country_name THEN iso.country_name
             ELSE users.country END AS **desirecountry**,
    -- 2.
    CASE  WHEN **desirecountry** = iso.country_name THEN **desirecountry**
            --ELSE Null END AS **Final_Country_Map_Name**
          
    FROM subs
    LEFT JOIN
    iso
    ON
    subs.location = iso.country_name
    LEFT JOIN
    users
    ON
    users.user_id = subs."user email"

当我使用第二个 CASE 条件时,逻辑失败,它没有给出预期的输出,它在“final_country_map_name”列中给了我一个空值,而不是“desirecountry”值=美国。任何小的帮助都会有所帮助,谢谢。例如:列名是:->

location | iso_country  |   country     | desirecountry  | final_country_map_name   &&& Column o/p are: -> 
U.s,      null,          United States,   United States,       null,
mysql redshift
  • 2 个回答
  • 151 Views
Martin Hope
mikelus
Asked: 2020-04-02 13:20:20 +0800 CST

一般来说,我们应该避免在 Redshift 中使用 ORM

  • 0

我的团队正在考虑将 Hibernate/Envers 用于 Redshift 数据的粒度时间点回滚解决方案。我听说使用带有 Redshift 的 ORM 不是一个好主意。使用 ORM(例如 hibernate 和 Redshift)是否有特别的缺点?

redshift orm
  • 1 个回答
  • 560 Views
Martin Hope
pnairn
Asked: 2019-10-08 16:24:25 +0800 CST

为什么 Redshift UNLOAD 提高了输出中 float4 字段的精度?

  • 1

我在 AWS Redshift 中创建了一个表,例如

CREATE TABLE exampleTableName (
  id       int identity(1,1),
  accId    varchar(16) encode zstd,
  amount   float4,

  primary key(id)
)
distkey(accId)
interleaved sortkey(accId);

表中的示例记录的amount字段值为120.12。

但是,当我尝试通过执行 UNLOAD 导出数据时,生成的文件(本质上是 CSV)对字段值具有额外的精度。

卸载命令:

UNLOAD ('SELECT * from exampleTableName')
TO 's3://bucket/prefixFile_'
IAM_ROLE 'XXX'
HEADER
ADDQUOTES
PARALLEL OFF
MAXFILESIZE AS 5gb
DELIMITER AS ',' 
GZIP;

结果输出中的字段值:(120.120003即它增加了 4 个小数位,原始数据集中没有)。

为什么会发生这种情况,如何防止附加精度(即小数位)作为 UNLOAD 命令的一部分输出?

redshift
  • 1 个回答
  • 419 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