Postgres: Exporting from public schema and importing into another schema - database

In postgres database, Is it possible to export data tables from public schema and import into another schema. I have having error while following the regular way of export and import.
Regards
Xian

Related

Exporting password protected file from sql

How can I export my MSSQL table into a password protected excel file? I am mentioning that I need to export my table into excel not importing.
Export the MSSQL data into excel by following the steps mentioned here
Export SQL server data to Excel and then add a password to your generated excel using the steps mentioned in this article Protect Excel with a Password

Postgresql: Copy different databases into one database with different schema

I have three postgresql databases in a server: db1,db2,db3. Now I want to save the tables in each db to a new db dbnew and distinguish it with schemas. Which means that there are three schemas in this database dbnew.db1,dbnew.db2,dbnew.db3. What is the easiest method to realize it?
(p.s.: I have dumped the database to local files.)
I test the answer from #a_horse_with_no_name, it seems to work but there is a new problem as follows:
If in db1 there is an extension like postgis, then I load db1 with psql and rename public to db1 and create a new schema named public. I could not create the extension postgis for public schema as it shows that extension postgis already exists. However if I use the command \dx, it shows that the extension is in schema db1 not in dbnew. Even if I use create EXTENSION postgis with schema public it doesn't work.
Based on backup/plain and restore using psql
I assume, that the schemas in dbnew are created and the rights to schema are set to the user doing all restoring using psql.
Somehow create sql files (backup plain in pgadmin3), the resulting files can be loaded into the dbnew database using psql, but they should piped through sed or grep, so that all tablenames get the schema prefix.
With somehow I meant, backup from original or first restore your backups into a temporary db, if they are no sql yet, and backup them as plain text.
Assuming all tables are stored in the public schema in the source databases
Import the first dump (by running psql ... -f dumpfile.sql), then rename the public schema to the new name:
alter schema schema public rename to db1;
Then re-create the public schema:
create schema public;
Now do the same thing for the other two database scripts.

CSV import in SQL - Add new updated existing

Is there a way to use the existing Import features from SQL Server Manager, to import a CSV file and if the record (by primary key)exists update record and if it doesnt exist then insert or do i have to write custom scripts to do this?
You will have to write something custom for this. The import wizard cannot do this.

Dmp file import create triggers error

I've taken a full database backup from one server to be moved to another using the following command (both using Oracle 11g):
exp SYSTEM/password#db1 full=y grants=y rows=y file=backup.dmp
And now when I want to import it into the other database using this:
imp SYSTEM/password file=backup.dmp fromuser=scott touser=scott
I first get an error related to database link:
Create Database Link Failed. ORA-01031: insufficient privileges.
If someone could explain why the imp command tried to link my new database to the source one which is not connected that would be helpful.
But otherwise that's not my main issue...
After that first error it continues with the import and imports all the rows and tables then at the end I get a series of errors related to 'CREATE TRIGGER's with error
ORA-00942: table or view does not exist
Am I missing something in my import parameters?
You don't seem to have privileges to create a database link, Please run this as sys user
SQL> grant create database link to scott;
Grant succeeded.
Then reimport the dumpfile, the triggers are failing because the related tables are not existing which i'm assuming the database link would be used to create the tables in the first place.
if you only want the scott user to be export then no need to connect to sys,
this will work,
export command
exp scott/pwd#db1 file=backup.dmp log=backup_log.log owner=scott
import command
imp scott/pwd#db? file=backup.dmp log=imp_backup.log full=y

SQL Server import export assistant error when importing time type

I'm trying to import a table from a txt file comma separated, the file was generated by the same SQL Server import/export assistant from my development database server.
Many tables has been imported by this way successfully.
The problem is when I have a column of the type date.
The message is: conversion unknown!
And then I cannot exec the package.
How can I solve this problem?

Resources