Skip to content

Commit 260e846

Browse files
authored
Merge pull request #241686 from AvijitkGupta/Split-COPY-azure_storage
Split copy azure storage
2 parents 8a35f4f + a8ed897 commit 260e846

File tree

4 files changed

+68
-39
lines changed

4 files changed

+68
-39
lines changed

articles/cosmos-db/postgresql/TOC.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@
247247
- name: Pg_azure_storage
248248
href: reference-pg-azure-storage.md
249249
displayName: pg_azure_storage, extensions
250+
- name: COPY
251+
href: reference-copy-command.md
252+
displayName: pg_azure_storage, copy
250253
- name: Limits and limitations
251254
href: reference-limits.md
252255
- name: Distributed SQL API

articles/cosmos-db/postgresql/howto-ingest-azure-blob-storage.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: mulander
66
ms.service: cosmos-db
77
ms.subservice: postgresql
88
ms.topic: how-to
9-
ms.date: 05/12/2023
9+
ms.date: 06/16/2023
1010
---
1111

1212
# How to ingest data using pg_azure_storage in Azure Cosmos DB for PostgreSQL
@@ -347,3 +347,4 @@ Congratulations, you just learned how to load data into Azure Cosmos DB for Post
347347
348348
- Learn how to create a [real-time dashboard](tutorial-design-database-realtime.md) with Azure Cosmos DB for PostgreSQL.
349349
- Learn more about [pg_azure_storage](reference-pg-azure-storage.md).
350+
- Learn about [Postgres COPY support](reference-copy-command.md).
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
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.
52+
53+
> [!div class="nextstepaction"]
54+
> [Reference azure_storage functions](reference-pg-azure-storage.md)
55+
56+
> [!div class="nextstepaction"]
57+
> [How to ingest data using pg_azure_storage](howto-ingest-azure-blob-storage.md)

articles/cosmos-db/postgresql/reference-pg-azure-storage.md

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,21 @@ author: AvijitkGupta
66
ms.service: cosmos-db
77
ms.subservice: postgresql
88
ms.topic: reference
9-
ms.date: 05/30/2023
9+
ms.date: 06/16/2023
1010
---
1111

1212
# pg_azure_storage extension
1313

1414
[!INCLUDE [PostgreSQL](../includes/appliesto-postgresql.md)]
1515

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. 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.
1717

18-
You can create the extension from psql by running:
18+
You can create the extension by running:
1919

2020
```postgresql
2121
SELECT create_extension('azure_storage');
2222
```
2323

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
49-
50-
| **Format** | **Description** |
51-
|------------|----------------------------------------------------------|
52-
| csv | Comma-separated values format used by PostgreSQL COPY |
53-
| tsv | Tab-separated values, the default PostgreSQL COPY format |
54-
| binary | Binary PostgreSQL COPY format |
55-
| text | A file containing a single text value (for example, large JSON or XML) |
56-
5724
## azure_storage.account_add
5825
Function allows adding access to a storage account.
5926

@@ -574,7 +541,8 @@ LIMIT 5;
574541

575542
## Next steps
576543

577-
Learn more about analyzing the dataset, along with alternative options.
544+
> [!div class="nextstepaction"]
545+
> [How to use Azure Blob Storage with the COPY command](reference-copy-command.md)
578546
579547
> [!div class="nextstepaction"]
580-
> [How to ingest data using pg_azure_storage](howto-ingest-azure-blob-storage.md)
548+
> [How to ingest data using pg_azure_storage](howto-ingest-azure-blob-storage.md)

0 commit comments

Comments
 (0)