migrating to agensgraph create foreign table error - postgresql

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);

Related

Cannot create Table in graph schema , Agensgraph

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!!!

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"

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;

How to copy table between two models in Mysql workbench?

I am doing some databese thing, I need copy one table from one model to another, but i try many ways there no effect.
Is there any way for doing this?
If you just want to do a single table through the MySQL Workbench.
In MySQL Workbench:
Connect to a MySQL Server
Expand a Database
Right Click on a table
Select Copy To Clipboard
Select Create Statement
A create statement for the table will be copied to your clipboard similar to the below:
CREATE TABLE `cache` (
`cid` varchar(255) NOT NULL DEFAULT '',
`data` longblob,
`expire` int(11) NOT NULL DEFAULT '0',
`created` int(11) NOT NULL DEFAULT '0',
`headers` text,
`serialized` smallint(6) NOT NULL DEFAULT '0',
PRIMARY KEY (`cid`),
KEY `expire` (`expire`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Create the table in the new database
Open a new SQL tab for executing queries (File->New Query Tab)
Alter the create table code to include the database to create the table on.
CREATE TABLE `databaseName`.`cache` (
`cid` varchar(255) NOT NULL DEFAULT '',
`data` longblob,
`expire` int(11) NOT NULL DEFAULT '0',
`created` int(11) NOT NULL DEFAULT '0',
`headers` text,
`serialized` smallint(6) NOT NULL DEFAULT '0',
PRIMARY KEY (`cid`),
KEY `expire` (`expire`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Then click the Execute button (looks like a lightening Bolt)
That will copy the table schema from one db to another using the MySQL workbench. Just refresh the tables in the database and you should see your newly added table
Select tab with source database
In menu: Server->Data Export
Select Schema and the Table as Schema Object
Select option Export to Self-Contained File and check Create Dump in a Single Transaction (self-contained only)
Copy full file path to clipboard
Start Export
Select tab with target database
In menu: Server->Data Import. Make sure your target database name is at the top left corner of the Data Import view
Select Import from self contained file and paste full file path from clipboard
Select Default Target Schema
Select Dump Content (Dump Structure and Data etc…)
Start Import
Your best option is probably to create a stripped down version of the model that contains the objects you want to carry over. Then open the target model and run File -> Include Model.... Select the stripped down source model and there you go.
You can just use a select statement. Here I am creating a duplicate of "original_table" table from the "original_schema" schema/database to the "new_schema" schema :
CREATE TABLE new_schema.duplicate_table AS
Select * from original_schema.original_table;
You can just put any select statement you need ,add a condition and select the columns :
CREATE TABLE new_schema.duplicate_table AS
SELECT column1, column2
FROM original_schema.original_table
WHERE column2 < 11000000;
I think it is worth mentioning that
a copied table may reference fields in tables of the original schema, that do not exist, in the schema where it's to be copied. It might be a good idea, to inspect the table for these discrepancies, before adding it to the other schema.
it's probably a good idea, to check engine compatibility (e.g. InnoDB vs MyISAM) and character set.
step 1 : Righit click on table > copy to clipboard > create statement
step 2: paste clipboard in the query field of workbench.
step 3: remove (``) from the name of the table and name of the model(schema)followed by a dot.
eg : `cusine_menus` -> schema_name.cusine_menus
execute
If you already have your table created and just want to copy the data, I'd recommend using the "Export Data Wizard" and "Import Data Wizard". It is basically choosing stuff in the program for exporting and then importing the data and is easy to use.
MySQL has an article on the wizards here: Table Data Export and Import Wizard
To copy data using the wizards, do the following:
Find the table in the list from which you want to copy data from.
Right click and choose "Table Data Export Wizard."
Choose the columns you wish to copy.
Choose a location to save a *.csv or *.json file with the copied data.
Find the table to insert the copied data to.
Right click and choose "Table data import wizard".
Choose the file you just exported.
Map the columns from the table you copied from to the table you insert to.
Press "Finish". The data is inserted as you chose.
In this post, we are going to show you how to copy a table in MySQL
First, this query will copy the data and structure, but the indexes are not included:
CREATE TABLE new_table SELECT * FROM old_table;
Second, this query will copy the table structure and indexes, but not data:
CREATE TABLE new_table LIKE old_table;
So, to copy everything, including database objects such as indexes, primary key constraint, foreign key constraints, triggers, etc., run these queries:
CREATE TABLE new_table LIKE old_table;
INSERT new_table SELECT * FROM old_table;
If you want to copy a table from one database to another database:
CREATE TABLE destination_db.new_table LIKE source_db.old_table;
INSERT destination_db.new_table
SELECT
*
FROM
source_db.old_table;
create table .m_property_nature like .m_property_nature;
INSERT INTO .m_property_nature SELECT * from .m_property_nature;
You can get the crate table query from table info and use the same query on different database instance.
show create table TABLENAME.content and copy the query;
Run the generated query on another Db instance connected.