Copying data in-database results in faster copy times because the data does not have to be loaded into or moved back out of SAS. You can run the COPY procedure in-database to copy PostgreSQL data in these situations:
In all cases, to copy data in-database, the USER= who you specify for the source location must have Read permission for that location. Also, the USER= for the target location must have Read permission for the source location and Write permission for the target location.
Here are some points to keep in mind when you copy data in-database:
To verify whether the COPY procedure ran in-database, specify MSGLEVEL=i in the OPTIONS statement.
This example shows how to copy data in PostgreSQL between schemas in a database. This example copies the table my_table from schema inschema into the schema outsch. The case of the table name is preserved because you specify PRESERVE_NAMES=YES. By specifying the REPLACE system option, you ensure that if the destination table already exists, it is replaced by the copy procedure. The ACCEL option for the PROC COPY statement is enabled by default. This option controls whether data is copied in-database.
libname pgin postgres user="myuser" database=userdb port=5432
server="pgserver.com" password=mypwd schema=inschema
preserve_names=yes;
libname pgout postgres user="myuser" database=userdb port=5432
server="pgserver.com" password=mypwd schema=outsch
preserve_names=yes;
options replace;
proc copy in=pgin out=pgout;
select my_table;
run;
quit;
proc contents data=pgout.my_table; run;
In the following example, you see how to copy table project_tab between different databases. The databases reside on different servers. For the copy to work, the user myuser must have permission to create a schema in the Pgout libref. The ACCEL option for the PROC COPY statement is enabled by default. This option controls whether data is copied in-database.
libname pgin postgres user="myuser" database=userdb port=5432
server=pgcloud password=cloudpwd schema=mysch1;
libname pgout postgres user="myuser" database=userpg port=5432
server=altpgsvr password=mypwd2 schema=mysch2;
proc copy in=pgin out=pgout;
select proj_tab;
run;
quit;
proc print data=pgout.proj_tab; run;