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中字段改成全小写

参考

相关推荐
l1t2 天前
DeepSeek总结的修复pgrust v0.2 #83:generate_series 聚合及其底层的两个成本 - #84
数据库·postgresql
2601_962181962 天前
数据库之PostgreSQL详解
数据库·postgresql
pnoker2 天前
IoT DC3 时序存储选型:四款数据库可插拔
数据库·物联网·postgresql·时序数据库·influxdb·tdengine·iotdb
头茬韭菜2 天前
图解 Fluss(五):Flink 接入与数据生命周期 —— Connector、表生命周期与冷热分层
大数据·flink·fluss
StarRocks_labs2 天前
StarRocks × Fluss × Paimon:流湖仓分析与 ETL 闭环
starrocks·flink·jni·native·paimon·湖仓·fluss
数智启示录2 天前
Doris精讲篇(六) 从第一批小文件到 -235:Doris 是怎样被正常写入拖死的
大数据·数据库·经验分享·面试·flink
StarRocks_labs2 天前
StarRocks 存算分离架构下的大规模实时导入优化实践
starrocks·flink·sstable·compaction·tablet·主键索引·存算分离架构
xuefuhe3 天前
PostgreSQL源码1:select 1
postgresql
IvorySQL3 天前
PostgreSQL 日报|内核多项缺陷修复与数据校验补丁推进(8 月 27 日)
数据库·postgresql·区块链
Cloud云卷云舒3 天前
【运营商数据库】实战淬炼,规模落地 | 中国移动HaishanDB年中总结会圆满召开
数据库·postgresql·ai-native·haishandb·移动云海山数据库