psql

will pg_restore overwrite the existing tables?

我是研究僧i 提交于 2019-12-05 00:07:56
Say I have two host servers s1 and s2. In both the servers i have a schema named n1, now i have made some changes to some of the tables present in schema n1 of s1. I want the same change to be done to schema n1 of server s2. what i am planning to do is to take a backup of the schema n1 of server s1 using pg_dump and restore in the server s2 using pg_restore. Now my question is ,since there is already the same schema n1 in the server s2 with the same set of tables. what the restore process will do? will it overwrite the existing tables or should i drop the existing schema of server s2 and

Error when trying to migrate postgresql db to mysql with workbench

試著忘記壹切 提交于 2019-12-04 18:55:47
问题 I am trying to migrate a postgresql database to mysql following this tutorial: http://mysqlworkbench.org/2012/11/how-to-migrate-postgresql-databases-to-mysql-using-the-mysql-workbench-migration-wizard/ I am experiencing this error when I try to test my connection Could not connect to Source DBMS [IM002][Microsoft][ODBC Driver Manager] Data soure name not found and no default driver specified (0)(SQLDriverConnect) ODBC connection string Driver=psqlodc;SERVER=127.0.0.1;PORT=5432;DATA... Does

how to use variables in a psql script

Deadly 提交于 2019-12-04 15:41:24
Here is my psql script, which does not work: \set path '''c:\\server\\data\\'''; COPY paymentMethods (name,regexString) FROM :path+'paymentMethods.csv' WITH (FORMAT csv, HEADER true); COPY priceLevels (name) FROM :path+'priceLevels.csv' WITH (FORMAT csv, HEADER false); psql complains about the syntax error at the + How can I change it so that it works, while having the actual path string mentioned just once? First of all, you are trying to concatenate two strings with + operator, but the SQL operator for concatenation is || , with that information, you could think the expected result would be

postgresql with jdbc and stored procedures (functions): ResultSet

别说谁变了你拦得住时间么 提交于 2019-12-04 14:38:38
问题 I just tried to call a stored function from the server (getStat), that is looking like this: create type stat as (type text, location text, number int); create function getStat() returns setof stat as 'select distinct table1.type, table1.location, table1.number from table1, table2 where table2.finding=10 order by number desc;' language 'sql'; Now here is the jdbc code: CallableStatement callable = null; String storedProc = "{call getStat(?, ?, ?)}"; try { callable = connection.prepareCall

Shebang for psql

↘锁芯ラ 提交于 2019-12-04 12:17:31
问题 I'm trying to write PostgreSQL script(s) but having a problem with shebang line #! /usr/bin/psql [ psql_args_here ] -f select now(); This gives me error as if I just entered psql without any arguments in command line. How do I do it right? 回答1: The problem is that psql don't skip the first line of the file. You could try #! /bin/sh exec sh -c "tail -n +3 $0 | psql -f -" select now(); or simply #! /bin/sh psql << E_O_SQL select now(); E_O_SQL 回答2: There is a even better solution. The first

customize pager in psql

╄→尐↘猪︶ㄣ 提交于 2019-12-04 08:16:43
问题 When I use psql , the command line tool of PostgreSQL, in interactive mode, it lists data as paginated output. However, because I use psql in a terminal application which can handle long outputs itself, I rather would like to get the whole output without the paginating with the annoying --more-- line. Is there any way to customise the paging behavior in psql ? I tried to set LESS in the surrounding shell environment to cat , but this din't help. Any suggestions? 回答1: From the fine psql manual

Docker compose postgresql service - can't create user and database during build?

喜欢而已 提交于 2019-12-04 06:01:58
I have wasted an entire day on this, and to say I'm not impressed by the unnecessary complexity of what should be a simple task - would be a gross understatement. Ok, having got that off my chest, I am building a django application using docker-machine, docker-compose, postgresql and redis - by following this tutorial . I have managed to get the basic tutorial to work - but it does not suit my needs, as I need to create a user and a database for my application - as opposed to using 'postgres' for both. I have used the answer from @dnephin to a similar question , and modified my code as follows

psql - write a query and the query's output to a file

烂漫一生 提交于 2019-12-04 02:15:12
In postgresql 9.3.1, when interactively developing a query using the psql command, the end result is sometimes to write the query results to a file: boron.production=> \o /tmp/output boron.production=> select 1; boron.production=> \o boron.production=> \q $ cat /tmp/output ?column? ---------- 1 (1 row) This works fine. But how can I get the query itself to be written to the file along with the query results? I've tried giving psql the --echo-queries switch: -e, --echo-queries Copy all SQL commands sent to the server to standard output as well. This is equivalent to setting the variable ECHO to

Insert SQL statements via command line without reopening connection to remote database

痴心易碎 提交于 2019-12-03 16:47:59
问题 I have a large amount of data files to process and to be stored in the remote database. Each line of a data file represents a row in the database, but must be formatted before inserting into the database. My first solution was to process data files by writing bash scripts and produce SQL data files, and then import the dump SQL files into the database. This solution seems to be too slow and as you can see involves an extra step of creating intermediary SQL file. My second solution was to

foreigner - remove foreign key

こ雲淡風輕ζ 提交于 2019-12-03 14:46:35
问题 I am trying to use mailboxer in my rails 4 app. A problem is arising when i try to deploy the db. The error occurs in creating the mailboxer conversations table, which has dependencies in notifications table. I am trying to remove the foreign key for notifications conversations. I created a migration which says: change_table :notifications do |t| t.remove_foreign_key :conversations However, the rake aborts and says a foreign key does not exist. rake aborted! An error has occurred, this and