You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcPostgresqlDAO.java
// System Information Functions: https://www.postgresql.org/docs/9.2/static/functions-info.html
62
62
sqlGetDB = "SELECT CURRENT_DATABASE()";
63
-
sqlIfTableExists = "SELECT * FROM PG_TABLES WHERE TABLENAME='#searchTable#'";
64
-
sqlCreateItemsTableIfNot = "CREATE TABLE IF NOT EXISTS #itemsManageTable# (itemid SERIAL NOT NULL, #colname# #coltype# NOT NULL, CONSTRAINT #itemsManageTable#_pkey PRIMARY KEY (itemid))";
65
-
sqlCreateNewEntryInItemsTable = "INSERT INTO items (itemname) SELECT itemname FROM #itemsManageTable# UNION VALUES ('#itemname#') EXCEPT SELECT itemname FROM items";
63
+
sqlIfTableExists = "SELECT * FROM PG_TABLES WHERE TABLENAME='\"#searchTable#\"'";
64
+
sqlDropTable = "DROP TABLE \"#tableName#\"";
65
+
sqlCreateItemsTableIfNot = "CREATE TABLE IF NOT EXISTS \"#itemsManageTable#\" (itemid SERIAL NOT NULL, #colname# #coltype# NOT NULL, CONSTRAINT #itemsManageTable#_pkey PRIMARY KEY (itemid))";
66
+
sqlCreateNewEntryInItemsTable = "INSERT INTO items (itemname) SELECT itemname FROM \"#itemsManageTable#\" UNION VALUES ('#itemname#') EXCEPT SELECT itemname FROM items";
66
67
sqlGetItemTables = """
67
68
SELECT table_name FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_schema=(SELECT table_schema \
68
-
FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_name='#itemsManageTable#') AND NOT table_name='#itemsManageTable#'\
69
+
FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_name='\"#itemsManageTable#\"') AND NOT table_name='\"#itemsManageTable#\"'\
69
70
""";
70
71
// The PostgreSQL equivalent to MySQL columns.column_type is data_type (e.g. "timestamp with time zone") and
71
72
// udt_name which contains a shorter alias (e.g. "timestamptz"). We alias data_type as "column_type" and
72
73
// udt_name as "column_type_alias" to be compatible with the 'Column' class used in Yank.queryBeanList
73
74
sqlGetTableColumnTypes = """
74
75
SELECT column_name, data_type as column_type, udt_name as column_type_alias, is_nullable FROM information_schema.columns \
75
-
WHERE table_name='#tableName#' AND table_catalog='#jdbcUriDatabaseName#' AND table_schema=(SELECT table_schema FROM information_schema.tables WHERE table_type='BASE TABLE' \
76
-
AND table_name='#itemsManageTable#')\
76
+
WHERE table_name='\"#tableName#\"' AND table_catalog='#jdbcUriDatabaseName#' AND table_schema=(SELECT table_schema FROM information_schema.tables WHERE table_type='BASE TABLE' \
77
+
AND table_name='\"#itemsManageTable#\"')\
77
78
""";
78
79
// NOTICE: on PostgreSql >= 9.5, sqlInsertItemValue query template is modified to do an "upsert" (overwrite
79
80
// existing value). The version check and query change is performed at initAfterFirstDbConnection()
80
-
sqlInsertItemValue = "INSERT INTO #tableName# (TIME, VALUE) VALUES( #tablePrimaryValue#, CAST( ? as #dbType#) )";
81
-
sqlAlterTableColumn = "ALTER TABLE #tableName# ALTER COLUMN #columnName# TYPE #columnType#";
81
+
sqlInsertItemValue = "INSERT INTO \"#tableName#\" (TIME, VALUE) VALUES( #tablePrimaryValue#, CAST( ? as #dbType#) )";
82
+
sqlCreateItemTable = "CREATE TABLE IF NOT EXISTS \"#tableName#\" (time #tablePrimaryKey# NOT NULL, value #dbType#, PRIMARY KEY(time))";
83
+
sqlAlterTableColumn = "ALTER TABLE \"#tableName#\" ALTER COLUMN #columnName# TYPE #columnType#";
84
+
sqlGetRowCount = "SELECT COUNT(*) FROM \"#tableName#\"";
82
85
}
83
86
84
87
@Override
@@ -92,7 +95,7 @@ public void initAfterFirstDbConnection() {
92
95
if (dbMeta.isDbVersionGreater(9, 4)) {
93
96
logger.debug("JDBC::initAfterFirstDbConnection: Values with the same time will be upserted (Pg >= 9.5)");
94
97
sqlInsertItemValue = """
95
-
INSERT INTO #tableName# (TIME, VALUE) VALUES( #tablePrimaryValue#, CAST( ? as #dbType#) )\
98
+
INSERT INTO \"#tableName#\" (TIME, VALUE) VALUES( #tablePrimaryValue#, CAST( ? as #dbType#) )\
96
99
ON CONFLICT (TIME) DO UPDATE SET VALUE=EXCLUDED.VALUE\
Copy file name to clipboardexpand all lines: bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcTimescaledbDAO.java
privatefinalStringsqlCreateHypertable = "SELECT created from create_hypertable('#tableName#', 'time')";
39
+
privatefinalStringsqlCreateHypertable = "SELECT created FROM create_hypertable('\"#tableName#\"', 'time')";
40
+
privatefinalStringsqlGetItemTables = "SELECT hypertable_name as table_name FROM timescaledb_information.hypertables WHERE hypertable_name != '\"#itemsManageTable#\"'";
38
41
39
42
@Override
40
43
publicPropertiesgetConnectionProperties() {
@@ -46,6 +49,10 @@ public Properties getConnectionProperties() {
0 commit comments