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.
Related
For a long time I have been working only with Oracle Databases and I haven't had much contact with PostgreSQL.
So now, I have a few questions for people who are closer to Postgres.
Is it possible to create a connection from Postgres to Oracle (oracle_fdw?) and perform selects on views in a different schema than the one you connected to?
Is it possible to create a connection from Postgres to Oracle (oracle_fdw?) and perform inserts on tables in the same schema as the one you connected to?
Ad 1:
Yes, certainly. Just define the foreign table as
CREATE FOREIGN TABLE view_1_r (...) SERVER ...
OPTIONS (table 'VIEW_1', schema 'USERB');
Ad 2:
Yes, certainly. Just define a foreign table on the Oracle table and insert into it. Note that bulk inserts work, but won't perform well, since there will be a round trip between PostgreSQL and Oracle for each row inserted.
Both questions indicate a general confusion between a) the Oracle user that you use to establish the connection and b) the schema of the table or view that you want to access. These things are independent: The latter is determined by the schema option of the foreign table definition, while the former is determined by the user mapping.
I've got PostgreSQL DB with multiple schemas and tables in that schemas. Every row in table have PRIMARY UUID like "Ref_Key" => "41bf3b1e-91f0-491c-a6bd-c48a17e7c252"
Is it possible to find row only by it UUID, without specifying schema and table?
No, that is not possible. You can only query tables that explicitly appear in the FROM clause of a SELECT statement.
Is it possible to create a foreign table, using Postgres Foreign Data Wrapper, that points to a view instead of a table?
Yes, it is possible!
The following query worked perfectly:
CREATE FOREIGN TABLE facts(name character varying(255))
SERVER my_server
OPTIONS (table_name 'facts');
Where facts is a view in my_server instead of a table.
Recently I had to do the same thing and here are the steps that worked for me. All these commands are run on the local postgreSQL DB.
CREATE EXTENSION postgres_fdw;
CREATE SERVER remote_server_name
FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host '10.10.10.10', port '5432', dbname 'remote_db_name');
CREATE USER MAPPING FOR local_user_name
SERVER remote_server_name
OPTIONS (user 'remote_user', password 'remote_password');
CREATE FOREIGN TABLE local_table_name (
id NUMERIC NOT NULL,
row TEXT,
another_row INTEGER,
whatever_row TEXT
)
SERVER remote_server_name
OPTIONS (schema_name 'public', table_name 'remote_table_name');
I have the same question.
In pgadmin4 for postgresql-11, if use GUI Command: Create -> Foreign Table...
on table, it works; but on view, it does't works, you will get a empty table.
for view, i use this code, it works:
IMPORT FOREIGN SCHEMA remote_schema_name
LIMIT TO (remote_view_name)
FROM SERVER remote_host_map_name INTO local_shema_name;
The reason is, for table, pgadmin4 can create columns same as remote table in constract SQL statement, but for view, it create no columns in constract SQL statement.
I'm brand new to MySQL Workbench and a have a bit of experience with databases (MS Access). I'm having trouble populating my fk with data. Here's what I have in my db schema:
2 tables Block and Set (Block having a pk Block_ID (type of INT); Set having fk to Block with fk name Set_Block_ID (type of INT).
1 to many relationship created from Block to Set tables linking Block_ID to Set_Block_ID. Relationship created, no problems
I populate the Block table with data. No problems
I then go to populate the Set table with data. I can see all my columns but not the fk. My question is why?
I have created the exact same db in MS Access and my fk is displayed in the linked table and I can populate it while MS Access makes sure referential integrity is enforced. I'm really brand new to Workbench and cant figure out why I cant see and populate my fk column.
Any help is appreciated!
Thanks!! =)
After having digested all the replies to my question (note sarcasm here) I have finally found a workaround way of solving the issue. To recap:
ISSUE:
created a simple 2 table relationship with Workbench with PK and FK (1 .. n relationship)
FK column not visible in Table Edit so not possible to enter any referencing data
SOLUTION:
installed SQLyog and connected to same server
opened same database and redid the simple 1 .. n relationship
FK column visible for editing in SQLyog
likewise, FK column visible for editing in Workbench
As I said, I'm new to this whole thing so I don't know what the problem was in Workbench. I just know it seems to be working fine now.
As you have noticed, the relationship drawing tool does not create actual foreign key constraints.
However, if double-click the referencing table and switch to the foreign-key tab, you can create references and specify the columns involved. This generates and maintains the visual linkage automatically:
I am developing a windows application and using Postgres as backend database. At some point in my application i am dynamically creating table e.g Table1, then Table2 and so on. In this way i have many dynamic table in my database. Now i provide a button "Clean Database", so i need to remove all those dynamic tables using SQL query. Should some one guide me how to write SQL Query that automatically delete all such tables?
You should just be able to say
DROP TABLE {tablename}
for each dynamically created table. Try that and see if it works.