An open API service indexing awesome lists of open source software.

https://github.com/yakubique/upsert-postgresql

Upsert anything to PostgreSQL
https://github.com/yakubique/upsert-postgresql

github-actions insert postgresql sql update upsert

Last synced: 3 months ago
JSON representation

Upsert anything to PostgreSQL

Awesome Lists containing this project

README

          

# Upsert to PostgreSQL

[![Coverage](./badges/coverage.svg)](./badges/coverage.svg)
[![Test `upsert-postgresql` action](https://github.com/yakubique/upsert-postgresql/actions/workflows/test-myself.yaml/badge.svg)](https://github.com/yakubique/upsert-postgresql/actions/workflows/test-myself.yaml)

Upsert anything to PostgreSQL

[Usage workflow](https://github.com/yakubique/upsert-postgresql/actions/workflows/test-myself.yaml)

Insert or update provided JSON array (_or file with JSON array_) to database. Conflicts would be resolved
by `column_to_match`

## Usage

```yaml
- name: Upsert
id: upsert
uses: yakubique/upsert-postgresql@v1.3
with:
input: |
[{ "id": 1, "value": "c", "test": 1 }, { "id": 2, "value": "b", "test": 2 }]
host: ${{ env.PG_HOST }}
port: ${{ env.PG_PORT }}
username: ${{ env.PG_USER }}
password: ${{ env.PG_PWD }}
db: ${{ env.PG_DB }}
ssl: 'false'
column_to_match: 'id'
table_name: 'test'
```

## Inputs

| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |
|-----------------|--------|----------|------------|---------------------------------------------------------------------------------------|
| input | string | true | | Input JSON/file |
| db | string | true | | PostgreSQL db |
| host | string | true | | PostgreSQL host |
| password | string | true | | PostgreSQL password |
| username | string | true | | PostgreSQL username |
| port | string | true | `"5432"` | PostgreSQL port (default: 5432) |
| table_name | string | true | | Name of table to upsert |
| column_to_match | string | true | | Primary column to match records (possible to pass multiple columns, comma separated) |
| table_schema | string | false | `"public"` | Table schema to upsert (default: 'public') |
| ssl | string | false | `"true"` | SSL enabled (default: 'true') |
| to_file | string | false | `"false"` | Save result to file (default: 'false') |
| from_file | string | false | `"false"` | Read query from file (default: 'false') |

## Outputs

| OUTPUT | TYPE | DESCRIPTION |
|--------|--------|---------------------|
| count | string | Upserted rows count |

----

[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/S6S1UZ9P7)