Skip to content
DuckDB community extension

psql

Support for PSQL, a piped SQL dialect for DuckDB

01 / SETUP

Install and load

Run these commands in a Haybarn SQL session. The extension is available from the community repository.

Haybarn 2.0.0 · SQL
INSTALL psql FROM community;
LOAD psql FROM community;

Try it in a temporary SQL session with psql already loaded. Queries run in this tab; examples using files or services need their own setup.

Using upstream DuckDB? Follow the maintainer’s installation instructions.

02 / QUERY

Usage example

SQL
from 'https://raw.githubusercontent.com/ywelsch/duckdb-psql/main/example/invoices.csv' |>
where invoice_date >= date '1970-01-16' |>
extend
  0.8 as transaction_fees,
  total - transaction_fees as income |>
where income > 1 |>
select
  customer_id,
  sum(income) as sum_income
  group by all |>
order by sum_income desc |>
limit 10 |>
as invoices
  join 'https://raw.githubusercontent.com/ywelsch/duckdb-psql/main/example/customers.csv'
    as customers
  on invoices.customer_id = customers.customer_id |>
select
  customer_id,
  last_name || ', ' || first_name as name,
  sum_income |>
order by sum_income desc, name;

Provided by ywelsch. Not yet verified on Haybarn 2.0.0.

Sample data & setup

About this extension

PSQL extends DuckDB's SQL with a pipe syntax to provide simple composable queries. It's a lightweight variant of piped languages such as PRQL and Kusto, yet leveraging the full power of DuckDB's SQL.

Every stage continues a FROM-first query on the result of the previous stage: A |> B is FROM (A) B. A stage can therefore contain anything that can follow the first table of a FROM-first query, such as joins, SELECT, WHERE, GROUP BY or ORDER BY, as well as an alias for that table, which needs AS, as in |> as invoices above.

Project overview from the community descriptor.

Documentation and resources

Project and build details
Repository
ywelsch/duckdb-psql
License
MIT
Maintainers
ywelsch
Written in
C++
Build source
13bea88da705
Build definition
Community descriptor