You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: COPY command on Azure Cosmos DB for PostgreSQL
3
+
description: Reference documentation on usage of COPY command
4
+
ms.author: avijitgupta
5
+
author: AvijitkGupta
6
+
ms.service: cosmos-db
7
+
ms.subservice: postgresql
8
+
ms.topic: reference
9
+
ms.date: 06/16/2023
10
+
---
11
+
12
+
# COPY command on Azure Cosmos DB for PostgreSQL
13
+
14
+
The [COPY](https://www.postgresql.org/docs/current/sql-copy.html) command is used to move data between files and database tables. `COPY` is a server-based command that requires access to the disk, usually limited to server administrators. However, Azure Cosmos DB for PostgreSQL operates as a Platform-as-a-Service (PaaS) solution, which means that users aren't granted superuser privileges. `COPY` command is thus not fully supported on the platform.
15
+
16
+
Alternatively, `\COPY` is a command available in `psql` and other client interfaces that facilitates direct interaction with the local file system of the machine where it is executed.
17
+
18
+
## Azure Blob Storage support
19
+
20
+
The `pg_azure_storage` extension overcomes disk access limitation by leveraging Azure Blob Storage as a data source. When enabled, the extension also enhances the built in `COPY` command with Azure Blob Storage support.
21
+
22
+
Load data into `github_users` table using the `COPY` command:
23
+
24
+
```postgresql
25
+
COPY github_users
26
+
FROM 'https://pgquickstart.blob.core.windows.net/github/users.csv.gz';
27
+
```
28
+
Currently the extension supports the following file formats:
29
+
30
+
|format|description|
31
+
|------|-----------|
32
+
|csv|Comma-separated values format used by PostgreSQL COPY|
33
+
|tsv|Tab-separated values, the default PostgreSQL COPY format|
34
+
|binary|Binary PostgreSQL COPY format|
35
+
|text|A file containing a single text value (for example, large JSON or XML)|
36
+
37
+
> [!Note]
38
+
> * Syntax and options supported remains likewise to Postgres Native [COPY](https://www.postgresql.org/docs/current/sql-copy.html) command, with following exceptions:
39
+
>
40
+
> -`FREEZE [ boolean ]`
41
+
> -`HEADER MATCH`
42
+
>
43
+
> *`COPY TO` syntax is yet not supported.
44
+
>
45
+
> *`\COPY` is a `psql` based command and doesn't support Azure Blob Storage integration.
46
+
>
47
+
> *`\COPY` does allow performing import\export on the cluster but requires moving\copying files across the network.
48
+
49
+
## Next steps
50
+
51
+
Learn more around usage of pg_azure_storage extension.
The pg_azure_storage extension allows you to load data in multiple file formats directly from Azure blob storage to your Azure Cosmos DB for PostgreSQL cluster. Containers with access level “Private” or “Blob” requires adding private access key.
16
+
The pg_azure_storage extension allows you to load data in multiple file formats directly from Azure blob storage to your Azure Cosmos DB for PostgreSQL cluster. Enabling the extension also unlocks new capabilities of the [COPY](reference-copy-command.md) command. Containers with access level “Private” or “Blob” requires adding private access key.
17
17
18
-
You can create the extension from psql by running:
18
+
You can create the extension by running:
19
19
20
20
```postgresql
21
21
SELECT create_extension('azure_storage');
22
22
```
23
23
24
-
## COPY FROM
25
-
26
-
`COPY FROM` copies data from a file, hosted on a file system or within `Azure blob storage`, to an SQL table (appending the data to whatever is in the table already). The command is helpful in dealing with large datasets, significantly reducing the time and resources required for data transfer.
27
-
28
-
```postgresql
29
-
COPY table_name [ ( column_name [, ...] ) ]
30
-
FROM { 'filename' | PROGRAM 'command' | STDIN | Azure_blob_url}
31
-
[ [ WITH ] ( option [, ...] ) ]
32
-
[ WHERE condition ]
33
-
```
34
-
> [!NOTE]
35
-
> Syntax and options supported remains likewise to Postgres Native [COPY](https://www.postgresql.org/docs/current/sql-copy.html) command, with following exceptions:
36
-
>
37
-
> -`FREEZE [ boolean ]`
38
-
> -`HEADER MATCH`
39
-
>
40
-
> `COPY TO` syntax is yet not supported.
41
-
42
-
### Arguments
43
-
#### Azure_blob_url
44
-
Allows unstructured data to be stored and accessed at a massive scale in block blobs. Objects in blob storage can be accessed from anywhere in the world via HTTPS. The storage client libraries are available for multiple languages, including .NET, Java, Node.js, Python, PHP, and Ruby.
45
-
46
-
### Option
47
-
#### format
48
-
Specifies the format of destination file. Currently the extension supports following formats
0 commit comments