My project is using SpringMVC, MyBatis, and PostgreSql.
In postgres, I have 2 servers: sv1, sv2.
I imported a table from sv2 into sv1 using:
import foreign schema public limit to (tbl2) from server sv2 into public;
But, when using DBUnit to do testing, I cannot insert data into the foreign table tbl2. The exception is:
ERROR org.dbunit.database.DatabaseDataSet - Table 'tbl2' not found in tableMap=org.dbunit.dataset.OrderedTableNameMap
How can I use foreign table in DBUnit?
You need to configure the DatabaseConfig.
databaseConfig.setProperty(PROPERTY_TABLE_TYPE, [array of string with table types]);
or
databaseConfig.setTableType([array with table types]);
or configure your bean and add property
<property name="tableType">
<array value-type="java.lang.String">
<value>TABLE</value>
<value>FOREIGN TABLE</value>
</array>
</property>
You can see the whole map of table types if you go to any of the implementations DatabaseMetadata and look for "TABLE".
Related
I'm trying to connect to PostgreSQL through DevExpress. The connection is returning the tables correctly except for the foreign tables.
Here's how I am connecting to PostgreSQL:
public DataConnectionParametersBase GetDataConnectionParameters(string name)
{
return new PostgreSqlConnectionParameters("xxx.xxx.xxx.xxx", XXXX, "dbName", "postgres_user", "XXXXXXXXX");
}
This is working well and returning all tables. However, the foreign tables are not showing.
Any ideas, please?
Try to trick your tool by using a VIEW on top of the foreign table:
CREATE VIEW x AS
SELECT * FROM your_foreign_table;
Most likely DevExpress checks pg_class just for the standard tables and views and isn't aware of new types of objects like foreign tables. But that's just an assumption.
This is how I defined the foreign table:
CREATE FOREIGN TABLE ftbl_employee (
id UUID,
name VARCHAR,
)
SERVER company_registry_dbserver
OPTIONS (schema_name 'company', table_name 'company_employee');
It created the foreign table successfully. However, when I list the foreign table, It has defaulted to public schema. See foreign_table_schema column:
> select * from information_schema.foreign_tables;
foreign_table_catalog
foreign_table_schema
foreign_table_name
foreign_server_catalog
foreign_server_name
sandbox
public
ftbl_employee
sandbox
company_registry_dbserver
I would like to map it into the company schema in our sandbox database server instead of the public schema.
The column information_schema.foreign_tables holds the schema where the foreign table is stored locally, not the schema of the table in the target database. So, there is no way you can create this foreign table in the schema company if it does not exist locally! You need to either locally run ..
CREATE SCHEMA company;
.. or live with the foreign table in the public schema. Keep in mind that a foreign table is nothing more than a "gateway" to a table that resides in a different database / server. If you wanna know more details on the foreign table, e.g. name or schema, check the view pg_foreign_table:
SELECT relname, ftoptions
FROM pg_foreign_table
JOIN pg_class ON ftrelid = oid;
beginner at SQL here, specifically using PostgreSQL. I'm trying to do something for a class here, but I keep receiving an error message and I'm not sure why. I've created a new database called "games", and I'm trying to create a basic table. The code is below.
The error message I receive is, [0A000] ERROR: cross-database references are not implemented: "games.games_schema.player_data" Position: 14
I can make the table in the default DB with postgreSQL fine, but why am I having issues trying to specifically create this table within this new Database?
CREATE DATABASE games;
CREATE TABLE games.games_schema.Player_Data
(Player_ID int,
Player_Name VARCHAR(255),
Player_System VARCHAR(255));
I thought the way I have my create table statement set up, is telling the server to create a table at that location. (database --> DBschema --> table)
Thanks for any help.
You created the games database, but that does not create a games_schema within it. It'll only create the schema Public (unless the default template has been modified) The solution is to either create a "games_schema" in the "games" database, or create your DB objects in the public schema.
Option 1: Create a schema.
create schema games_schema;
create table games_schema.player_data( ... );
Option 2: Use the Public schema.
create table player_data( ... );
My choice would be option 1, as I never allow anything other than extensions and Postgres supplied objects in public.
I created a foreign data wrapper table named t_user into mySchema.
IMPORT FOREIGN SCHEMA public LIMIT TO (t_user)
FROM SERVER myServer INTO mySchema;
The myServer side t_user added some column, but the foreign table didn't update accordingly.
I tried to delete the foreign table t_user, but it was used by my view and materialized view t_user, so the deletion failed.
Any ideas on how to update this table?
As you have seen, the foreign table definition does not change when the underlying table changes.
If all you did is add a column, you can use ALTER FOREIGN TABLE to add a corresponding column to the foreign table. That should work even if views depend on the foreign table.
For example, if the column is of type text, you can do:
ALTER FOREIGN TABLE t_user ADD COLUMN my_column text;
I have master-slave architecture. On the slave I have an Oracle database with two schemas, e.g. TEST1 and TEST2.
I have all objects (e.g. EMPLOYEES) stored in schema TEST1, and user TEST1 (or admin) has given read only privileges on TEST1.EMPLOYEES to TEST2, so when I use TEST1.EMPLOYEES in a query on the Oracle database I can access its data.
How can I implement the same using Oracle foreign data wrapper in postgres 9.5 because I have credentials for TEST2 and not TEST1?
When I try to access the foreign table it give an error saying that TEST2.EMPLOYEES does not exist.
You can easily do that if you define the user mapping with the credentials of user TEST2 and the foreign table with the schema option, i.e.
CREATE FOREIGN TABLE ... OPTIONS (schema 'TEST1', table 'EMPLOYEES');