mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-31 10:30:33 +03:00 
			
		
		
		
	
		
			
				
	
	
		
			81 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			81 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| $PostgreSQL: pgsql/contrib/dblink/doc/execute,v 1.4 2006/03/11 04:38:29 momjian Exp $
 | |
| ==================================================================
 | |
| Name
 | |
| 
 | |
| dblink_exec -- Executes an UPDATE/INSERT/DELETE on a remote database
 | |
| 
 | |
| Synopsis
 | |
| 
 | |
| dblink_exec(text connstr, text sql [, bool fail_on_error])
 | |
| dblink_exec(text connname, text sql [, bool fail_on_error])
 | |
| dblink_exec(text sql [, bool fail_on_error])
 | |
| 
 | |
| Inputs
 | |
| 
 | |
|   connname
 | |
|   connstr
 | |
| 
 | |
|     If two arguments are present, the first is first assumed to be a specific
 | |
|     connection name to use. If the name is not found, the argument is then
 | |
|     assumed to be a valid connection string, of standard libpq format,
 | |
|     e.g.: "hostaddr=127.0.0.1 dbname=mydb user=postgres password=mypasswd"
 | |
| 
 | |
|     If only one argument is used, then the unnamed connection is used.
 | |
| 
 | |
|   sql
 | |
| 
 | |
|     sql statement that you wish to execute on the remote host, e.g.:
 | |
|        insert into foo values(0,'a','{"a0","b0","c0"}');
 | |
| 
 | |
|   fail_on_error
 | |
| 
 | |
|     If true (default when not present) then an ERROR thrown on the remote side
 | |
|     of the connection causes an ERROR to also be thrown locally. If false, the
 | |
|     remote ERROR is locally treated as a NOTICE, and the return value is set
 | |
|     to 'ERROR'.
 | |
| 
 | |
| Outputs
 | |
| 
 | |
|   Returns status of the command, or 'ERROR' if the command failed.
 | |
| 
 | |
| Notes
 | |
|   1) dblink_open starts an explicit transaction. If, after using dblink_open,
 | |
|      you use dblink_exec to change data, and then an error occurs or you use
 | |
|      dblink_disconnect without a dblink_close first, your change *will* be
 | |
|      lost.
 | |
| 
 | |
| Example usage
 | |
| 
 | |
| select dblink_connect('dbname=dblink_test_slave');
 | |
|  dblink_connect
 | |
| ----------------
 | |
|  OK
 | |
| (1 row)
 | |
| 
 | |
| select dblink_exec('insert into foo values(21,''z'',''{"a0","b0","c0"}'');');
 | |
|    dblink_exec
 | |
| -----------------
 | |
|  INSERT 943366 1
 | |
| (1 row)
 | |
| 
 | |
| select dblink_connect('myconn','dbname=regression');
 | |
|  dblink_connect
 | |
| ----------------
 | |
|  OK
 | |
| (1 row)
 | |
| 
 | |
| select dblink_exec('myconn','insert into foo values(21,''z'',''{"a0","b0","c0"}'');');
 | |
|    dblink_exec
 | |
| ------------------
 | |
|  INSERT 6432584 1
 | |
| (1 row)
 | |
| 
 | |
| select dblink_exec('myconn','insert into pg_class values (''foo'')',false);
 | |
| NOTICE:  sql error
 | |
| DETAIL:  ERROR:  null value in column "relnamespace" violates not-null constraint
 | |
| 
 | |
|  dblink_exec
 | |
| -------------
 | |
|  ERROR
 | |
| (1 row)
 |