Skip to main content

How To Connect

The Tangram SQL Service implements the PostgreSQL wire protocol, so tools or libraries that work with PostgreSQL can be used directly to connect to the Tangram SQL service.

Examples

Using psql

# replace `localhost` with your own Tangram OS SQL service host
# replace `duckdb` with the SQL engine id or alias for the engine you want to connect
psql -p 9200 --host localhost -U tangram -d duckdb

Using Tangram CLI

# choose the Tangram OS instance to connect
use local
# connect to one sql engine
sql-engine connect duckdb

The above will connect to the built-in DuckDB sql engine of the seleced Tangram OS instance and you can start to type and execute SQL statements like using psql.

Using JDBC

PostgreSQL JDBC driver

// https://mvnrepository.com/artifact/org.postgresql/postgresql
implementation("org.postgresql:postgresql:42.7.5")

import java.sql.*;
import java.util.Properties;

public class TangramSQLConnect {

public static void main (String arg[]) throws SQLException{
String url = "jdbc:postgresql://localhost:9200/duckdb";
Properties props = new Properties();
props.setProperty("user", "<your Tangram OS user name>");
props.setProperty("password", "<your Tangram OS access token>");

try(Connection conn = DriverManager.getConnection(url, props)) {
String sqlQuery = "select * from iceberg.test.nyc_taxi";
PreparedStatement st = conn.prepareStatement(sqlQuery);
ResultSet rs = st.executeQuery();
//do things with the result set
}
}

}

Using Python psycopg2

For information about how to install psycopg and the difference between psycopg and psycopg-binary, see the official psycopg documentation.

import psycopg2

conn = psycopg2.connect(host="127.0.0.1",
port=9200,
user="<your-tangram-os-user>",
password="<your-tangram-os-access-token>",
dbname="duckdb")