How to find the current database type

We have one SQL script to execute on several types of databases. Is it possible to get the type of the current database on which the SQL script is running?

Note. We cannot use non-standard SQL ie TSQL, etc.

+3
source share
4 answers

No, there is nothing in ANSI SQL about defining a database provider.

+4
source

No, not in the SQL statement.

If you use JDBC, you should be able to extract enough information from java.sql.DatabaseMetaData . Take a look getDatabaseProductName.

I assume that similar features are available for other platforms.

+1
source

ANSI SQL , . , , . , SQL . , . SQL , . , .

, , , SQL script. , try-catch ANSI SQL...

0
SELECT *
FROM information_schema.sql_implementation_info
WHERE implementation_info_name LIKE 'DBMS%'
    ;

:

 implementation_info_id | implementation_info_name | integer_value | character_value | comments 
------------------------+--------------------------+---------------+-----------------+----------
 17                     | DBMS NAME                |               | PostgreSQL      | 
 18                     | DBMS VERSION             |               | 09.01.0002      | 
(2 rows)

I can’t say whether the presence of these elements is required in the information_schema. I think so.

matrix of information scheme support

0
source

All Articles