Metadata-Version: 2.5
Name: ahi-sql
Version: 0.2.1
Summary: Small, dependency-light SQL helpers for AHI (safe identifiers, placeholders).
Project-URL: Homepage, https://adaptivehealthintelligence.github.io/ahi-python-packages/
Project-URL: Documentation, https://adaptivehealthintelligence.github.io/ahi-python-packages/
Author: Adaptive Health Intelligence
License: MIT
Keywords: ahi,sql
Requires-Python: >=3.11
Description-Content-Type: text/markdown

# ahi-sql

Small, dependency-light SQL helpers — the bits people otherwise hand-roll and
get subtly wrong: quoting identifiers, generating bind placeholders, and building
the DDL for a staged lookup table.

```python
from ahi.sql import quote_identifier, placeholders

quote_identifier("user table")  # '"user table"'
placeholders(3, style="qmark")  # '?, ?, ?'   (Athena)
placeholders(3, style="named")  # ':1, :2, :3' (Redshift Data API)
```

> Quote **identifiers** with `quote_identifier`. Quote **values** by passing them
> as bind parameters to your driver — never by string-formatting them in.

It also builds the DDL behind a staged lookup table — text only, so you can read
and adapt the statement without running anything:

```python
from ahi.sql import create_external_id_table, drop_table

create_external_id_table(
    "ahi_ids_a1b2c3d4",  # table
    "s3://my-bucket/scratch/ahi_ids_a1b2c3d4/",  # location
    "encounter_id",  # column
    database="scratch",
)
# CREATE EXTERNAL TABLE "scratch"."ahi_ids_a1b2c3d4" ( "encounter_id" bigint ) ...

drop_table("ahi_ids_a1b2c3d4", database="scratch")
# DROP TABLE IF EXISTS "scratch"."ahi_ids_a1b2c3d4"
```

`ahi.aws.stage_id_table` runs these for you; see the
[`ahi-aws` README](../ahi-aws/README.md).

Part of [ahi-python-packages](https://github.com/adaptivehealthintelligence/ahi-python-packages).
