Netezza ODBC connection - equivalent of "use database"
Asked Answered
I

4

6

After connecting to a Netezza system is there any way to switch the database? For instance, in MSSQL one could send the command use database_name in order to switch to the database_name.

Is there anything in Netezza like "use" on mssql?

http://technet.microsoft.com/en-us/library/ms188366.aspx

My reason for asking is in regards to metadata queries; I can only access _v_table of the "currently connected database".

Indrawn answered 14/2, 2014 at 16:30 Comment(0)
T
11

Prior to Version 7.0 there wasn't an equivalent to USE. You had to log in to specific databases on the server however you can still access any object using. database.schema.objectname

Post Version 7.0 the equivalent is Set Catalog

SET CATALOG <database_name> 

Regarding your specific inquiry. Please consider using _V_TABLE_XDB instead of _V_TABLE. This system table should provide you with a list of all tables, not just those in the database you are connected to.

Towboat answered 18/2, 2014 at 3:55 Comment(0)
S
5

If you're using NPS v7.0+, then the SET CATALOG command will connect you to a different database dynamically (without having to disconnect and reconnect). The beauty of this command is that it can be submitted from an ODBC/JDBC client as well as in an nzsql script.

Strow answered 12/8, 2014 at 1:31 Comment(2)
This is the answer I was looking for.Adore
This should have been considered as the best answer.Slime
T
3

In Netezza you can to other database with following command -

nzsql -u <username> -pw <password> -db <databasename> -host <netezza server IP>

hope this will help you.

Toddler answered 16/2, 2014 at 5:46 Comment(0)
M
0

As we know while executing any query in netezza we need to specify database name in connection url , which we should to make dynamic according to required database on which we have to perform operation, so in case of simple java code we can use the below Case 1) and in case of spring boot we can use below Case 2).

Case 1) before executing any query in netezza we can execute statement as

SET CATALOG #database name#;

so it will automatically switch to database provided in set command.

Case 2) We can switch the database in netezza with runtime switching of database

  1. Use Apache basic data source (BasicDataSource) instead of DriverManagerDataSource while creating bean for datasource

  2. Execute - jdbcTemplate.execute("SET CATALOG #database name#") Before executing any query.

Moderato answered 27/9, 2019 at 7:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.