-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PostgreSQL as a possible viewer #3121
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# PostgreSQL | ||
|
||
[PostgreSQL](https://www.postgresql.org/docs/) is a powerful, open source object-relational database system. It is the most [popular](https://survey.stackoverflow.co/2024/technology#most-popular-technologies-database) database by application developers for a few years running. [pgai](https://github.com/timescale/pgai) is a PostgreSQL extension that allows you to easily ingest huggingface datasets into your PostgreSQL database. | ||
|
||
|
||
## Run PostgreSQL with pgai installed | ||
|
||
You can easily run a docker container containing PostgreSQL with pgai. | ||
|
||
```bash | ||
docker run -d --name pgai -p 5432:5432 \ | ||
-v pg-data:/home/postgres/pgdata/data \ | ||
-e POSTGRES_PASSWORD=password timescale/timescaledb-ha:pg17 | ||
``` | ||
|
||
Then run the following command to install pgai into the database. | ||
|
||
```bash | ||
docker exec -it pgai psql -c "CREATE EXTENSION ai CASCADE;" | ||
``` | ||
|
||
You can then connect to the database using the `psql` command line tool in the container. | ||
|
||
```bash | ||
docker exec -it pgai psql | ||
``` | ||
|
||
or using your favorite PostgreSQL client using the following connection string: `postgresql://postgres:password@localhost:5432/postgres | ||
` | ||
|
||
Alternatively, you can install pgai into an existing PostgreSQL database. For instructions on how to install pgai into an existing PostgreSQL database, follow the instructions in the [github repo](https://github.com/timescale/pgai). | ||
|
||
## Create a table from a dataset | ||
|
||
To load a dataset into PostgreSQL, you can use the `ai.load_dataset` function. This function will create a PostgreSQL table, and load the dataset from the Hugging Face Hub | ||
in a streaming fashion. | ||
|
||
```sql | ||
select ai.load_dataset('rajpurkar/squad', table_name => 'squad'); | ||
``` | ||
|
||
You can now query the table using standard SQL. | ||
|
||
```sql | ||
select * from squad limit 10; | ||
``` | ||
|
||
<Tip> | ||
Full documentation for the `ai.load_dataset` function can be found [here](https://github.com/timescale/pgai/blob/main/docs/load_dataset_from_huggingface.md). | ||
</Tip> | ||
|
||
## Import only a subset of the dataset | ||
|
||
You can also import a subset of the dataset by specifying the `max_batches` parameter. | ||
This is useful if the dataset is large and you want to experiment with a smaller subset. | ||
|
||
```sql | ||
SELECT ai.load_dataset('rajpurkar/squad', table_name => 'squad', batch_size => 100, max_batches => 1); | ||
``` | ||
|
||
## Load a dataset into an existing table | ||
|
||
You can also load a dataset into an existing table. | ||
This is useful if you want more control over the data schema or want to predefine indexes and constraints on the data. | ||
|
||
```sql | ||
select ai.load_dataset('rajpurkar/squad', table_name => 'squad', if_table_exists => 'append'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you also add the link inside
parquet_process.md
?