Using the gsql Meta-Command \COPY to Import Data

The gsql tool of GaussDB(DWS) provides the \copy meta-command to import data.

\copy Command

For details about the \copy command, see Table 1.

Table 1 \copy meta-command

Syntax

Description

\copy { table [ ( column_list ) ] |

( query ) } { from | to } { filename |

stdin | stdout | pstdin | pstdout }

[ with ] [ binary ] [ oids ] [ delimiter

[ as ] 'character' ] [ null [ as ] 'string' ]

[ csv [ header ] [ quote [ as ]

'character' ] [ escape [ as ] 'character' ]

[ force quote column_list | * ] [ force

not null column_list ] ]

You can run this command to import or export data after logging in to the database on any gsql client. Different from the COPY statement in SQL, this command performs read/write operations on local files rather than files on database servers. The accessibility and permissions of the local files are restricted to local users.

NOTE:

\copy only applies to small-batch data import with uniform formats but poor error tolerance capability. GDS or COPY is preferred for data import.

Parameter Description

Examples

Create the target table copy_example.
1
2
3
4
5
6
7
8
create table copy_example
(
	col_1 integer,
	col_2 text,
	col_3 varchar(12),
	col_4 date,
	col_5 time
);