当前位置:网站首页>Flinksql 读写pgsql
Flinksql 读写pgsql
2022-07-06 23:51:00 【zs_bigdata】
一. 代码
StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env, EnvironmentSettings.inStreamingMode());
AbstractJdbcCatalog catalog = JdbcCatalogUtils.createCatalog(
"myPgsql",
"staging",
"username",
"password",
"jdbc:postgresql://xxx:port"
);
tableEnv.registerCatalog("myPgsql", catalog);
tableEnv.useCatalog("myPgsql");
tableEnv.useDatabase("staging");
boolean staging = catalog.tableExists(new ObjectPath("staging", "medical.hospital_department"));
System.out.println(staging);
System.out.println(Arrays.toString(tableEnv.listCatalogs()));
System.out.println(Arrays.toString(tableEnv.listDatabases()));
//System.out.println(Arrays.toString(tableEnv.listTables()));
tableEnv.executeSql("select id,name from `medical.hospital_department`").print();
//sql api
tableEnv.executeSql(
"CREATE TABLE hospital_position (\n" +
" id string,\n" +
" department_id string,\n" +
" waypoint_id STRING,\n" +
" zone_id STRING,\n" +
" PRIMARY KEY (id) NOT ENFORCED\n" +
") WITH (\n" +
" 'connector' = 'jdbc',\n" +
" 'url' = 'jdbc:postgresql://xxxxx:port/数据库',\n" +
" 'username' = 'xx', " +
" 'password' = 'xxxx', " +
" 'table-name' = 'schema名.表名'\n" +
")"
);
2 踩坑
如果pgsql使用了schema,name此时表名需要``转义,否则会报找不到medical object
// `medical.hospital_department` 一定要转义
tableEnv.executeSql("select id,name from `medical.hospital_department`").print();
边栏推荐
猜你喜欢
Digital innovation driven guide
漏电继电器LLJ-100FS
DOM-节点对象+时间节点 综合案例
[JS component] date display.
EGR-20USCM接地故障继电器
JVM (XX) -- performance monitoring and tuning (I) -- Overview
论文阅读【Open-book Video Captioning with Retrieve-Copy-Generate Network】
1. AVL tree: left-right rotation -bite
Leakage relay jd1-100
How Alibaba cloud's DPCA architecture works | popular science diagram
随机推荐
漏电继电器JD1-100
数字化创新驱动指南
1.AVL树:左右旋-bite
Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game
5. 数据访问 - EntityFramework集成
Cve-2021-3156 vulnerability recurrence notes
Reading the paper [sensor enlarged egocentric video captioning with dynamic modal attention]
Design, configuration and points for attention of network arbitrary source multicast (ASM) simulation using OPNET
Under the trend of Micah, orebo and apple homekit, how does zhiting stand out?
Photo selector collectionview
Leetcode: maximum number of "balloons"
论文阅读【MM21 Pre-training for Video Understanding Challenge:Video Captioning with Pretraining Techniqu】
AIDL 与Service
[reading of the paper] a multi branch hybrid transformer network for channel terminal cell segmentation
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
[论文阅读] A Multi-branch Hybrid Transformer Network for Corneal Endothelial Cell Segmentation
【js组件】date日期显示。
sql优化常用技巧及理解
实现网页内容可编辑
集群、分布式、微服务的区别和介绍