branch: elpa/pg
commit d19abd4f7b9ad3bef9f54391181935d0c4a19d6c
Author: Eric Marsden <[email protected]>
Commit: Eric Marsden <[email protected]>

    Add support for PostgreSQL variants openGauss and pgsqlite.
---
 CHANGELOG.md  |  2 ++
 pg.el         | 18 ++++++++++++------
 test/Makefile | 24 ++++++++++++++++++++++++
 3 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5ec380cbaa7..0e614ba0a46 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,8 @@
   PostgreSQL version, or variants that support the older protocol) is the 
length of the key used to
   authenticate requests to cancel an ongoing query.
 
+- Add detection code and workarounds for the PostgreSQL variants OpenGauss (by 
Huawei) and pgsqlite.
+
 
 ## [0.59] - 2025-08-31
 
diff --git a/pg.el b/pg.el
index 819d3036ed6..f28bccc5f42 100644
--- a/pg.el
+++ b/pg.el
@@ -518,6 +518,10 @@ Uses connection CON. The variant can be accessed by 
`pgcon-server-variant'."
               (setf (pgcon-server-variant con) 'cedardb))
              ((cl-search "Yellowbrick Database" version)
               (setf (pgcon-server-variant con) 'yellowbrick))
+             ((cl-search "pgsqlite " version)
+              (setf (pgcon-server-variant con) 'pgsqlite))
+             ((cl-search "openGauss" version)
+              (setf (pgcon-server-variant con) 'opengauss))
              ;; TODO: find a better detection method for ArcadeDB
              ((string-suffix-p "/main)" version)
               (setf (pgcon-server-variant con) 'arcadedb))
@@ -532,17 +536,19 @@ Uses connection CON. The variant can be accessed by 
`pgcon-server-variant'."
              ;; pg_settings table.
              ;;
              ;;   "SELECT current_setting('omni_disk_cache_enabled', true)"
-             ((let* ((res (pg-exec-prepared con "SELECT setting FROM 
pg_catalog.pg_settings WHERE name=$1"
-                                            `(("omni_disk_cache_enabled" . 
"text"))))
-                     (rows (pg-result res :tuples)))
+             ((let* ((res (ignore-errors
+                            (pg-exec-prepared con "SELECT setting FROM 
pg_catalog.pg_settings WHERE name=$1"
+                                              `(("omni_disk_cache_enabled" . 
"text")))))
+                     (rows (and res (pg-result res :tuples))))
                 (unless (null rows)
                   (setf (pgcon-server-variant con) 'alloydb))))
              ;; TODO: we could also detect CitusDB in the same way by checking 
for citus.cluster_name
              ;; setting for example, but in practice it is very PostgreSQL 
compatible so identifying
              ;; it as a variant doesn't seem mandatory.
              ((let* ((sql "SELECT 1 FROM information_schema.schemata WHERE 
schema_name=$1")
-                     (res (pg-exec-prepared con sql '(("_timescaledb_catalog" 
. "text")))))
-                (pg-result res :tuples))
+                     (res (ignore-errors
+                            (pg-exec-prepared con sql 
'(("_timescaledb_catalog" . "text"))))))
+                (and res (pg-result res :tuples)))
               (setf (pgcon-server-variant con) 'timescaledb)))))
     ('ydb
      (pg-exec con "SET search_path = 'public'")))
@@ -3799,7 +3805,7 @@ Uses database connection CON."
     ;; QuestDB doesn't really support schemas.
     ('questdb (list "sys" "public"))
     ('arcadedb nil)
-    ((or 'risingwave 'octodb)
+    ((or 'risingwave 'octodb 'pgsqlite)
      (let ((res (pg-exec con "SELECT DISTINCT table_schema FROM 
information_schema.tables")))
        (apply #'append (pg-result res :tuples))))
     ('vertica
diff --git a/test/Makefile b/test/Makefile
index ecc3a549a84..d099a153104 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1100,6 +1100,25 @@ test-polardb: test-pg.el
        ${DOCKER} stop polardb
 
 
+# Huawai openGauss fork of PostgreSQL
+#
+# https://hub.docker.com/r/opengauss/opengauss
+test-opengauss: test-pg.el
+       ${DOCKER} run --rm --name opengauss \
+           --pull=newer \
+           --publish 127.0.0.1:5488:5488 \
+           -e TZ=UTC-7:00 \
+           -e LANG=en_US.UTF8 \
+           -e LC_CTYPE=en_US.UTF8 \
+           -e GS_PASSWORD="PGelt44^" \
+           -e GS_USERNAME=pgeltestuser \
+           -e GS_PORT=5488 \
+           -d docker.io/opengauss/opengauss:7.0.0-RC2.B015
+       sleep 20
+       PGURI=postgresql://pgeltestuser:PGelt44^@127.0.0.1:5488/postgres 
$(MAKE) test
+       ${DOCKER} stop opengauss
+
+
 # Very limited PostgreSQL support: there is no pg_type table so we can't 
retrieve information
 # regarding the OID of builtin types. We have to be careful during the 
initialization sequence not
 # to send the query "SET datestyle = 'ISO'", which would fail and cause the 
network connection to be
@@ -1323,6 +1342,11 @@ test-chrondb: test-pg.el
        PGURI=postgresql://[email protected]:5432/chrondb $(MAKE) test
 
 
+# https://github.com/erans/pgsqlite?tab=readme-ov-file
+test-pgsqlite: test-pg.el
+       pgsqlite --port 7778 --in-memory &
+       PGURI=postgresql://[email protected]:7778/pgeltestdb $(MAKE) test
+
 
 # Create and populate a new database with information concerning works by 
Shakespeare.
 # Data from https://github.com/catherinedevlin/opensourceshakespeare

Reply via email to