Cannot create Table in graph schema , Agensgraph - postgresql

I am trying to import Northwind dateset as mentioned in this tutorial 'https://bitnine.net/tutorial/tutorial_eng.html?ckattempt=1', I did the same process but when i create new foreign table 'categories' or for other table it give the same error: "cannot create table in graph schema".
DROP GRAPH northwind CASCADE;
CREATE GRAPH northwind;
SET graph_path = northwind;
DROP SERVER northwind;
CREATE SERVER northwind FOREIGN DATA WRAPPER file_fdw;
CREATE FOREIGN TABLE categories (CategoryID int,
CategoryName varchar(15),
Description text,
Picture bytea
)
SERVER northwind
OPTIONS (FORMAT 'csv', HEADER 'true', FILENAME 'D:\northwind \categories.csv', delimiter ',', quote '"', null '');
Error:"cannot create table in graph schema"
There is any solution for it please let me know.
agensgraph : (AgensGraph 2.1.2, based on PostgreSQL 10.4)
OS: Windows 10 X64
Same question: migrating to agensgraph create foreign table error
Thanks in advance!!!

Related

Postgres - CREATE FOREIGN TABLE based on other table

I'm looking way to simplify CREATE FOREIGN command, so do need to specify all columns and types.
What I'm doing now (using file_fdw server):
CREATE FOREIGN TABLE temp_table_csv
(id integer, name text)
SERVER csv_log_server
OPTIONS ( filename 'path_to_file.csv', format 'csv');
What I would like to do:
CREATE FOREIGN TABLE temp_table_csv
(like example_table)
SERVER csv_log_server
OPTIONS ( filename 'path_to_file.csv', format 'csv');
Using LIKE or similar command so Postgres can read structure out of there
But it says "like is not supported"

migrating to agensgraph create foreign table error

So, I'm taking a first look at migrating a PostgreSQL db to agensgraph db.
I'm using the manual https://bitnine.net/wp-content/uploads/2016/11/AgensGraph_Quick_Guide.pdf
first export as csv:
SET CLIENT_ENCODING TO 'utf8';
\COPY samples.samples TO
'C:\Users\garyn\Documents\graph_migration\pg_csv\samples_samples.csv'
WITH DELIMITER E'\t' CSV;
And on page 20 I follow the first steps, creating the foreign table:
CREATE EXTENSION file_fdw;
CREATE SERVER import_server FOREIGN DATA WRAPPER file_fdw;
CREATE FOREIGN TABLE vlabel_profile ( id graphid, properties text) SERVER import_server
OPTIONS( FORMAT 'csv', HEADER 'false',
FILENAME 'C:\Users\garyn\Documents\graph_migration\pg_csv\samples_samples.csv',
delimiter E'\t');
ERROR: cannot create table in graph schema
SQL state: XX000
Now, I haven't set any column names (as header=false) and I haven't changed the id graphid, properties text since the manual says it is setting up the table, but it states the file directory, any ideas how to get past this error? I'm back to being a noob.
The next steps will be:
CREATE FOREIGN TABLE elabel_profile ( id graphid, start graphid, "end" graphid, properties text) SERVER import_server OPTIONS( FORMAT 'csv', HEADER 'false', FILENAME '/path/file.csv', delimiter E'\t');
Then execute the import
CREATE VLABEL test_vlabel; LOAD FROM vlabel_profile AS profile_name CREATE (a:test_vlabel =row_to_json(profile_name)::jsonb);
CREATE ELABEL test_elabel; LOAD FROM elabel_profile AS profile_name MATCH (a:test_vlabel), (b:test_vlabel) WHERE (a).id::graphid = (profile_name).start AND (b).id::graphid = (profile_name).end CREATE (a)-[:test_elabel]->(b);
------------ UPDATE ------------
I'm now trying with the northwind dataset, again following the agens tutorial: https://bitnine.net/tutorial/english-tutorial.html
DROP GRAPH northwind CASCADE;
CREATE GRAPH northwind;
SET graph_path = northwind;
DROP SERVER northwind;
CREATE SERVER northwind FOREIGN DATA WRAPPER file_fdw;
CREATE FOREIGN TABLE categories (
CategoryID int,
CategoryName varchar(15),
Description text,
Picture bytea
)
SERVER northwind
OPTIONS (FORMAT 'csv', HEADER 'true', FILENAME 'D:\northwind\categories.csv', delimiter ',', quote '"', null '');
Same error
I have tried to create a foreign table with northwind dataset you mentioned but it works just fine for me as you see the below screen shot.
I installed the agensgraph and tried the sample with its latest version which is 2.1.0 since I didn't have agensgraph on my window OS.
If you let me know the version of agensgraph you are currently using and how you are accessing to agensgraph, I would be able to help you out more.
re: cannot create table in graph schema
This is an error you will get when your schema is the same as the name of a graph - or there is some other problem related to the default schema.
The default schema is called public. To check your current schema enter
select current_schema();
If it's not public you can set it with
set schema public;
then try to create a table
create table mytable(id int);

Tables are getting created in public schema rather than the other newly created schema in PostgreSQL using PgAdmin4

I am working on PostgreSQL and I want tables in a different schema, not in public.
I am using PgAdmin4. I created one schema and selected the same schema and open the Query Tool. I ran the following query to create the table:
DROP TABLE IF EXISTS ClassToTable;
CREATE TABLE ClassToTable (className varchar(4000), fieldName varchar(4000), tableName varchar(4000) );
But the table is getting created in public schema , rather than the schema which i have created and selected while executing the query.
Can you please help me in resolving this issue or any workaround??

Logging records in a postgresql database

I am having trouble thinking of a way to copy three fields out of a database into and append them to another table along with the current date. Basically what I want to do is:
DB-A: ID (N9), Name (C69), Phone (N15) {and a list of other fields I dont care about}
DB-B: Date (Todays date/time), Nane, Address, Phone (as above)
Would be great is this was a trigger in the DB on add or update of DB-A.
Greg
Quick and dirty using postgres_fdw
CREATE EXTENSION IF NOT EXISTS postgres_fdw ;
CREATE SERVER extern_server FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host 'foreignserver.co.uk', port '5432', dbname 'mydb');
CREATE USER MAPPING FOR myuser SERVER extern_server OPTIONS (user 'anotheruser');
-- Creating a foreign table based on table t1 at the server described above
CREATE FOREIGN TABLE foreign_t1 (
dba INT,
name VARCHAR(9),
phone VARCHAR(15)
)
SERVER extern_server OPTIONS (schema_name 'public', table_name 't1');
--Inserting data to a new table + date
INSERT INTO t2 SELECT dba,name,phone,CURRENT_DATE FROM foreign_t1;
-- Or just retrieving what you need placing the current date as a column
SELECT dba,name,phone,CURRENT_DATE FROM foreign_t1;

Why is postgres_fdw double-qualifying schemas?

Using postgres_fdw, I need to create the foreign tables in a specified schema to prevent name collisions. To isolate the issue I've been having, I set up two test postgres databases on the same cluster, import_test and export_test. Export_test has a table, foreign_schema.aa. On the server import_test, after doing the other FDW prerequisites, I ran:
CREATE FOREIGN TABLE local_schema.aa(
id serial NOT NULL,
dat text
) SERVER export_server OPTIONS (table_name 'foreign_schema.aa');
Then:
SELECT * FROM local_schema.aa;
When I do this, I get:
ERROR: relation "local_schema.foreign_schema.aa" does not exist
CONTEXT: Remote SQL command: SELECT id, dat FROM local_schema."foreign_schema.aa"
If I don't do any schema qualification, as in:
CREATE FOREIGN TABLE aa(
id serial NOT NULL,
dat text
) SERVER export_server OPTIONS (table_name 'aa');
And move the aa table to the public schema, the select works just fine.
If the command "SELECT id, dat FROM local_schema."foreign_schema.aa" is literally being run on the remote server, it's obvious why it doesn't work: local_schema."foreign_schema.aa" really doesn't exist on the remote server. For some reason, the postgres_fdw appears to be prepending the name given for table_name with the schema of the foreign table.
I need to specify the schema in the select query, because if I don't it doesn't see the foreign table. Achieving the schema qualification by preceding the select with setting the search path doesn't help either.
Is there anything I am doing wrong? If not, is there a workaround that will let me schema-qualify the foreign table?
EDIT: Per #Craig Ringer's suggestions, here's the self-contained psql input:
CREATE USER test_user SUPERUSER PASSWORD 'password';
SET ROLE test_user;
CREATE DATABASE import;
CREATE DATABASE export;
\c export test_user
CREATE SCHEMA export_schema;
CREATE TABLE export_schema.aa (
id serial PRIMARY KEY,
dat text
);
\c import test_user
CREATE EXTENSION postgres_fdw;
CREATE SERVER export_server
FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host 'localhost', dbname 'export', port '5432');
CREATE USER MAPPING FOR test_user
SERVER export_server
OPTIONS (user 'test_user', password 'password');
CREATE SCHEMA import_schema;
CREATE FOREIGN TABLE import_schema.aa(
id serial NOT NULL,
dat text
) SERVER export_server OPTIONS (table_name 'export_schema.aa');
SELECT * FROM import_schema.aa;
Which yields this output:
ERROR: relation "import_schema.export_schema.aa" does not exist
CONTEXT: Remote SQL command: SELECT id, dat FROM import_schema."export_schema.aa"
Forgot to come back with resolution. Turns out sometime around the time I posted my bug report, the docs on postgres_fdw were updated. See the section "F.31.1.2. Object Name Options" and the schema_name option on this page: http://www.postgresql.org/docs/current/static/postgres-fdw.html.
I quote the mailing list reply:
"Use: OPTIONS (schema_name 'export_schema', table_name 'aa'); above.
Thanks,
Stephen"
So to resolve, just specify the foreign schema name in the schema_name option parameter.