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

参考

相关推荐
x-cmd9 小时前
[250202] DocumentDB 开源发布:基于 PostgreSQL 的文档数据库新选择 | Jekyll 4.4.0 发布
数据库·postgresql·开源
Leven1995271 天前
Flink (十三) :Table API 与 DataStream API 的转换 (一)
数据库·sql·flink
好记性+烂笔头1 天前
3 Flink 运行架构
大数据·架构·flink
字节侠1 天前
Flink2支持提交StreamGraph到Flink集群
大数据·flink·streamgraph·flink2·jobgraph
好记性+烂笔头1 天前
10 Flink CDC
大数据·flink
程序猿阿伟1 天前
《大数据时代“快刀”:Flink实时数据处理框架优势全解析》
大数据·flink
程序员学习随笔2 天前
PostgreSQL技术内幕24:定时任务调度插件pg_cron
数据库·postgresql
字节全栈_vBr2 天前
Flink Forward Asia 2024 - 总结和展望(附PPT下载链接)
大数据·flink
GIS小小研究僧3 天前
PostgreSQL 数据库备份与还原
数据库·postgresql·oracle·postgis
J.Kuchiki4 天前
【PostgreSQL内核学习 —— (WindowAgg(一))】
数据库·学习·postgresql