flink1.20 连接 postgres

sql 复制代码
CREATE CATALOG mypg WITH(
    'type' = 'jdbc',
    'default-database' = 'postgres',
    'username' = 'postgres',
    'password' = '',
    'base-url' = 'jdbc:postgresql://10.50.108.42:5432'
);

create table soc_all (
WATERMARK FOR collectorreceipttime AS collectorreceipttime - INTERVAL '5' SECOND
)
WITH(
    'connector' = 'jdbc',
    'url' = 'jdbc:postgresql://10.50.108.42:5432/postgres',
    'username' = 'postgres',
    'password' = '',
    'driver' = 'org.postgresql.Driver'
)
LIKE `mypg`.`postgres`.`public.soc_local`;

CREATE TABLE sink_pg(
    srcUserName STRING,
    eventTime TIMESTAMP(3),
    ip STRING,
    baseline STRING,
    alert BOOLEAN
)
WITH (
    'connector' = 'jdbc',
    'url' = 'jdbc:postgresql://10.50.108.42:5432/postgres',
    'table-name' = 'alert',
    'username' = 'postgres',
    'password' = '',
    'driver' = 'org.postgresql.Driver'
);


-- 改成全部小写
insert into sink_pg
select
    '' as srcusername,
    ceil(collectorreceipttime  to hour) as eventtime,
    srcaddress as ip,
    '' as baseline,
    false
from soc_all
where collectorreceipttime  >= '2024-10-16'
and collectorreceipttime  < '2024-10-27'
and srcaddress <> ''
limit 100;

踩坑

postgres字段类型 timestamp 默认 timestamp(6),需要转换后才能作为水印字段

sql 复制代码
ALTER TABLE public.soc_local
ALTER COLUMN collectorReceiptTime TYPE TIMESTAMP(3);

postgresql 大小写不敏感

pg 中查询大写字段需要加双引号,但是flink sql 不支持引号,所以用flinksql查询pg大写字段会报错,见参考链接。

py 复制代码
Caused by: java.lang.IllegalArgumentException: open() failed.ERROR: column "collectorreceipttime" does not exist
  Hint: Perhaps you meant to reference the column "soc_local.collectorReceiptTime".

解决方案,把pg中字段改成全小写

参考

相关推荐
花酒锄作田7 小时前
Postgres - Listen/Notify构建轻量级发布订阅系统
python·postgresql
IvorySQL13 小时前
PostgreSQL 技术日报 (4月7日)|内核开发新动态,多项功能优化落地
数据库·postgresql·开源
IvorySQL14 小时前
PostgreSQL 技术日报 (4月6日)|内核补丁与性能优化速递
数据库·postgresql·开源
IvorySQL14 小时前
PostgreSQL 技术日报 (4月5日)|六大核心补丁进展,生产环境必看
数据库·postgresql·开源
IvorySQL14 小时前
走进高校,走近开源|IvorySQL 社区即将亮相应急管理大学开源学术报告会
数据库·postgresql·开源
你都会上树?19 小时前
Ubuntu22 安装PostgreSQL
数据库·postgresql
IvorySQL19 小时前
PostgreSQL & IvorySQL 技术交流 Meetup・郑州站| 4.18 线下开讲,只聊硬核技术
数据库·postgresql·开源
大大大大晴天21 小时前
Flink技术实践-90%都会踩的状态坑
大数据·flink
lifallen1 天前
Flink Agent 与 Checkpoint:主循环闭环与 Mailbox 事件驱动模型
java·大数据·人工智能·python·语言模型·flink
白眼黑刺猬1 天前
如何构建 Flink SQL 任务的血缘分析
大数据·面试·职场和发展·flink