dblink

postgresql: INSERT INTO … (SELECT * …)

北慕城南 提交于 2019-11-28 03:44:04
I'm not sure if its standard SQL: INSERT INTO tblA (SELECT id, time FROM tblB WHERE time > 1000) What I'm looking for is: what if tblA and tblB are in different DB Servers . Does PostgreSql gives any utility or has any functionality that will help to use INSERT query with PGresult struct I mean SELECT id, time FROM tblB ... will return a PGresult* on using PQexec . Is it possible to use this struct in another PQexec to execute an INSERT command. EDIT: If not possible then I would go for extracting the values from PQresult* and create a multiple INSERT statement syntax like: INSERT INTO films

postgres dblink escape single quote

左心房为你撑大大i 提交于 2019-11-28 03:02:38
问题 Related Link: String literals and escape characters in postgresql Here is my error: ERROR: type "e" does not exist Here is my query: SELECT * FROM dblink('host=theHostName port=1234 dbname=theDBName user=theUser password=thePassword', E'SELECT field_1, CASE WHEN field_2 IS NOT NULL THEN \'inactive\' ELSE \'active\' END AS field_status FROM the_table ') AS linkresults(field_1 varchar(20),field_2 varchar(8)) If I use double quotes, remove the backslash escape for the single quotes and remove

PostgreSQL: Query has no destination for result data

你离开我真会死。 提交于 2019-11-27 21:36:20
问题 I am trying to fetch data from remote db by using dblink through function but getting an error "query has no destination for result data". I am using plpgsql language to do the same. Function : CREATE OR REPLACE FUNCTION fun() RETURNS text AS $$ begin select dblink_connect( 'port=5432 dbname=test user=postgres password=****'); WITH a AS ( SELECT * FROM dblink( 'SELECT slno,fname,mname,lname FROM remote_tbl' ) AS t (slno int, fname text, mname text, lname text) ) , b AS ( INSERT INTO temptab1

How do I do large non-blocking updates in PostgreSQL?

好久不见. 提交于 2019-11-26 21:39:11
I want to do a large update on a table in PostgreSQL, but I don't need the transactional integrity to be maintained across the entire operation, because I know that the column I'm changing is not going to be written to or read during the update. I want to know if there is an easy way in the psql console to make these types of operations faster. For example, let's say I have a table called "orders" with 35 million rows, and I want to do this: UPDATE orders SET status = null; To avoid being diverted to an offtopic discussion, let's assume that all the values of status for the 35 million columns

Postgres Error: More than one row returned by a subquery used as an expression

浪尽此生 提交于 2019-11-26 16:13:02
问题 I have two separate databases. I am trying to update a column in one database to the values of a column from the other database: UPDATE customer SET customer_id= (SELECT t1 FROM dblink('port=5432, dbname=SERVER1 user=postgres password=309245', 'SELECT store_key FROM store') AS (t1 integer)); This is the error I am receiving: ERROR: more than one row returned by a subquery used as an expression Any ideas? 回答1: Technically , to repair your statement, you can add LIMIT 1 to the subquery to

How do I do large non-blocking updates in PostgreSQL?

爱⌒轻易说出口 提交于 2019-11-26 06:20:15
问题 I want to do a large update on a table in PostgreSQL, but I don\'t need the transactional integrity to be maintained across the entire operation, because I know that the column I\'m changing is not going to be written to or read during the update. I want to know if there is an easy way in the psql console to make these types of operations faster. For example, let\'s say I have a table called \"orders\" with 35 million rows, and I want to do this: UPDATE orders SET status = null; To avoid