Skip to content

Commit

Permalink
feat: blueprint on Postgres Queries task (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
shrutimantri authored Jan 31, 2025
1 parent 149d67b commit 1577a31
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions flows/postgres-queries.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
id: postgres-queries
namespace: company.team

tasks:
- id: init_products
type: io.kestra.plugin.jdbc.postgresql.Queries
url: "jdbc:postgresql://{{ secret('POSTGRES_HOST') }}:5432/postgres"
username: "{{ secret('POSTGRES_USERNAME') }}"
password: "{{ secret('POSTGRES_PASSWORD') }}"
sql: |
CREATE TABLE IF NOT EXISTS products(
product_id SERIAL PRIMARY KEY,
product_name varchar(100),
product_category varchar(50),
brand varchar(50)
);
INSERT INTO products VALUES(1, 'streamline turn-key systems','Electronics','gomez') ON CONFLICT (product_id) DO NOTHING;
INSERT INTO products VALUES(2, 'morph viral applications','Household','wolfe') ON CONFLICT (product_id) DO NOTHING;
INSERT INTO products VALUES(3, 'expedite front-end schemas','Household','davis-martinez') ON CONFLICT (product_id) DO NOTHING;
INSERT INTO products VALUES(4, 'syndicate robust ROI','Outdoor','ruiz-price') ON CONFLICT (product_id) DO NOTHING;
fetchType: NONE

extend:
title: Use Postgres Queries to run multiple queries
description: >-
This flow demonstrates using Postgres Queries task to run multiple
queries in a single task.
This flow can be used a seed flow which can create a table and insert
some sample rows in the table. The flow is idempotent in nature, i.e.
no matter how many times you run the flow, the flow will execute
successfully. Here are the different queries that we execute in the
`init_products` task:
1. The first query creates `products` table if it does not already exist.
In case it exists, it does nothing.
2. The next 4 queries inserts data into the table. In case, the row with
the same primary key already exists, it does nothing.
Thus, the flow can be run multiple times without any side effect.
tags:
- Postgres
ee: false
demo: false
meta_description: This flow uses Postgres Queries task to run multiple queries.

0 comments on commit 1577a31

Please sign in to comment.