The problem of openGauss database connection schema - open-gauss

we encountered a problem when migrating the database from oracle to guassdb. It is a compatible version with postgresdb, which uses schema,
For example, select * from table1
Now because gauss uses schema, our table is in a01
The query becomes select * from a01.table1, which causes all the codes to be changed during the migration. The schema is added to the front of each table name, which is too big. Is there a better solution, such as adding schema to the url connection, because we only use one schema for each project

You can configure the user's search_path in the openGauss database. This parameter can also be configured through the url parameter in the jdbc.
for example: jdbc:postgresql://localhost:5432/mydatabase?currentSchema=a1

Related

2 databases on the one H2 instance

I have JPA Repository with #Query that joins tables from other DBs, that located on the same server.
SELECT id,co.name from Agenc a inner join[other_db_mame].[schema_name].[table_name] co .....
I want to write integration tests to cover the flow with this query.
In intégration tests I use H2 DB
And my question is, how to correctly configure H2 DB to have 2 DBs and make this query work?
Maybe there is a way, to create another db via scripts, or smth like this?
H2 supports direct access only to one database at once, but you can create linked tables to tables from other databases.
To create a linked table, you can use a CREATE LINKED TABLE command:
https://h2database.com/html/commands.html#create_linked_table
CREATE LINKED TABLE targetTableName('', 'jdbcURL', 'username', 'password', 'sourceTableName');
You can also link the whole schema with LINK_SCHEMA function:
https://h2database.com/html/functions.html#link_schema
CALL LINK_SCHEMA('targetSchemaName', '', 'jdbcURL', 'username', 'password', 'sourceSchemaName');
Note that format of fully-qualified table name in H2 (and in the SQL Standard) is catalogName.schemaName.tableName. H2 supports only one catalog (and its name is the same as a name of database) and you can't define additional catalogs. Non-standard -syntax with [identifier] is not accepted by H2 unless you use a MSSQLServer compatibility mode. In this mode you can use that syntax, but you can't have different names of catalogs anyway, so if they are fixed in your application, you have a problem.
Actually H2 can ignore the specified name of catalog if IGNORE_CATALOGS setting is set to TRUE:
https://h2database.com/html/commands.html#set_ignore_catalogs
SET IGNORE_CATALOGS TRUE;
But if combinations of schema and table name aren't unique in your original configuration, there is nothing to do with H2. You can't create different tables with the same schema and table name in H2 in any way.

Discovering tables on an Oracle Database return an empty list

When creating a connection to an Oracle database in icCube 'Select existing DB Tables' is returning an empty list of tables.
The connection is fine and I can query the schema creating SQL queries.
The user is used as the schema name, but Oracle uses upper case as default for the schema names. The connection uses the user that is case insensitive.
Just, change the name of your user to the upper case version : USER_1

Schema name prefix issue in SQL query

I have WMADMIN schema. This schema is configured as connection credential in websphere datasource.
I have table in other schema/user OCS_JOBS. But the problem is my application looking for the table in WMADMIN schema.
It looks i need to prefix schemaname OCS_JOBS in SQL query to run them.
Is there any other way to run the SQL query the table which is in other user/schema without prefixing the other schema name
You can create a SYNONYM see it here: http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_7001.htm

How should I read the data from different oracle schema using ado.net?

The database user has got two schemas. I need to read the data from a specific schema using ado.net. I am using OleDbConnection object to create the connection to database. Appreciate your answers.
Use SCHEMA_NAME.TABLE_NAME in your queries.
If you don't specify a schema, Oracle will look into the current schema. The schema is by default the connexion user (so if you connect with USER1 and query TABLE1, Oracle will look for the table USER1.TABLE1). You can change your current schema at any time during a session with:
ALTER SESSION SET CURRENT_SCHEMA=SCHEMA2;
You can also use synonyms to point to the correct table.

Possible to link to another database link?

We have an existing database link in an Oracle database that links to data in a Sql Server database. Now, a 2nd Oracle database needs to use that same data. Due to security setup, the 2nd Oracle database cannot "see" the Sql Server database, but it can see the 1st Oracle database.
If we create a database link in the 2nd Oracle database that points to the 1st Oracle database, will we be able to query data from the Sql Server database in the 2nd Oracle database by going through 2 database links? Would the query syntax look like this:
SELECT * FROM myTable#2ndLink#1stLink
Has anyone done something like this before?
Vincent's solution will work, and another solution is to create a synonym instead of a view.
DB1:
CREATE SYNONYM X FOR MyTable#sqlServerDB
DB2:
(assumes db link to DB1 connects as owner of synonym)
SELECT * from X#DB1
I'm not sure this synthax would work (although it would be interesting to test it I can not do it right now). However, even if it doesn't work, you can still create a view in Database 1 that points to a table in your SQL Server Database. From Database 2, you could then query:
SELECT * FROM myView#db1
That would point to the correct table.

Resources