# PostgreSQL

> For the complete documentation index, see [llms.txt](https://kotlin.github.io/dataframe/llms.txt).

Kotlin DataFrame supports reading from a [PostgreSQL](https://www.postgresql.org) database using JDBC.

API reference: [PostgreSql](https://kotlin.github.io/dataframe/api-docs/dataframe-jdbc/org.jetbrains.kotlinx.dataframe.io.db/-postgre-sql/index.html), [readSqlTable](https://kotlin.github.io/dataframe/api-docs/dataframe-jdbc/org.jetbrains.kotlinx.dataframe.io/read-sql-table.html)

Requires the [dataframe-jdbc module](modules.html#dataframe-jdbc), which is included by default in the general [dataframe artifact](modules.html#dataframe-general) and in [%use dataframe](setupkotlinnotebook.html#integrate-kotlin-dataframe) for Kotlin Notebook.

You’ll also need [the official PostgreSQL JDBC driver](https://jdbc.postgresql.org):

Gradle project:

```KOTLIN
dependencies {
    implementation("org.postgresql:postgresql:$version")
}
```

Kotlin Notebook:

```KOTLIN
USE {
    dependencies("org.postgresql:postgresql:$version")
}
```

The actual Maven Central driver version can be found [here](https://mvnrepository.com/artifact/org.postgresql/postgresql).

## Read

A [DataFrame](dataframe.html) can be loaded from a database in several ways:

* a user can read data from a SQL table by a given name ([readSqlTable](readsqldatabases.html)),

* as a result of a user-defined SQL query ([readSqlQuery](readsqldatabases.html)), or

* from a given `ResultSet` ([readResultSet](readsqldatabases.html)). It is also possible to load all data from non-system tables, each into a separate `DataFrame` ([readAllSqlTables](readsqldatabases.html)).

See [Read from SQL databases](readsqldatabases.html) for more details.

```KOTLIN
val url = "jdbc:postgresql://localhost:5432/testDatabase"
val username = "postgres"
val password = "password"

val dbConfig = DbConnectionConfig(url, username, password)

val tableName = "Customer"

val df = DataFrame.readSqlTable(dbConfig, tableName)
```

