# RPostgres

> R RPostgres package for PostgreSQL databases. Use for PostgreSQL connections with modern DBI interface.

- Skill: `leolin990405/rpostgres` (Agent Skill)
- Install (CLI): `npx get-skill add leolin990405/rpostgres`
- Raw SKILL.md: https://api.skillmd.com/api/skills/leolin990405/rpostgres/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: LeoLin990405 (https://skillmd.com/u/leolin990405)
- Updated: 2026-11-14
- Page: https://skillmd.com/skills/leolin990405/rpostgres

---


# RPostgres Package

PostgreSQL database interface.

## Connect

```r
library(DBI)
library(RPostgres)

con <- dbConnect(
  Postgres(),
  dbname = "mydb",
  host = "localhost",
  port = 5432,
  user = "user",
  password = "password"
)

# With connection string
con <- dbConnect(
  Postgres(),
  "postgresql://user:password@localhost:5432/mydb"
)
```

## Basic Operations

```r
# Query
df <- dbGetQuery(con, "SELECT * FROM users LIMIT 100")

# Write table
dbWriteTable(con, "new_table", df)

# Append
dbWriteTable(con, "existing", df, append = TRUE)

# Overwrite
dbWriteTable(con, "existing", df, overwrite = TRUE)
```

## Parameterized Queries

```r
dbGetQuery(con,
  "SELECT * FROM users WHERE id = $1 AND status = $2",
  params = list(123, "active")
)
```

## COPY Protocol (Fast)

```r
# Fast bulk insert
dbWriteTable(con, "big_table", big_df, copy = TRUE)
```

## Schemas

```r
# Specify schema
dbWriteTable(con, Id(schema = "analytics", table = "events"), df)
dbReadTable(con, Id(schema = "analytics", table = "events"))
```

## Disconnect

```r
dbDisconnect(con)
```

