Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I confirm a database is Postgres & what version it is using SQL?

Tags:

sql

postgresql

I'm building an installer for an application. The user gets to select a datasource they have configured and nominate what type of database it is. I want to confirm that the database type is indeed Postgres, and if possible, what version of Postgres they are running by sending a SQL statement to the datasource.

like image 994
modius Avatar asked Sep 19 '08 11:09

modius


1 Answers

Try this:

mk=# SELECT version();
                                            version                                            
-----------------------------------------------------------------------------------------------
 PostgreSQL 8.3.3 on i486-pc-linux-gnu, compiled by GCC cc (GCC) 4.2.3 (Ubuntu 4.2.3-2ubuntu7)
(1 row)

The command works too in MySQL:

mysql> select version();
+--------------------------------+
| version()                      |
+--------------------------------+
| 5.0.32-Debian_7etch1~bpo.1-log | 
+--------------------------------+
1 row in set (0.01 sec)

There is no version command in sqlite as far as I can see.

like image 107
Matthias Kestenholz Avatar answered Oct 19 '22 23:10

Matthias Kestenholz