PostgreSQL native library for Tarantool programming language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long. 3.4KB

pg-tarantool - PostgreSQL connector for Tarantool

Getting Started


  • Tarantool 1.10+ with headers (tarantool && tarantool-dev packages)
  • PostgreSQL 9.1+ headers (libpq-dev package)
  • OpenSSL headers (libssl-dev package)
  • libuuid headers (buuid-dev package)
  • Recommended: lua-cjon and lpeg


Clone repository and then build it using CMake:

hg clone
cd pg-tarantool && cmake . 
make install

You can also use LuaRocks:

luarocks install


pg = require('pg_tarantool')
link = pg.connect({host = localhost, user = 'user', pass = 'pass', db = 'db', sslmode = 'required', connections = 10})
data = link:query("SELECT 1 as ONE, '2' as TWOSTRING") 

API Documentation

Connect to a database.
Returns link (connections pool).


  • host - a hostname to connect
  • port - a port numner to connect
  • user - username
  • password - a password
  • dbname - a database name
  • sslmode - a ssl mode used in this connection (see Table 31-1. SSL Mode Descriptions) (default = ‘disable’)
  • connections - connection pool size (0 means do not create connection pool, just establish single connection) (default = ‘0’)


  • link, database connections pool,

Executes a statement with given arguments in printf-like style.
Arguments can be: numeric, string or table types. They will be escaped and formatted automatically.


  • {result1}, {result2}, ... on success
  • false, error description, on error


### `link:query("SELECT %d AS a, %s AS b", 42, 'string_value')
- - - a: 42
      b: "string_value"

Prepare a SQL statement.


  • statement object on success
  • false, error description, on error

Statement object methods:

  • persist(true) — do not deallocate current statement after execution
  • deallocate() — deallocate current statement
  • execute(arg1, arg2...) — execute current statement with given arguments
  • (...) — alias to execute


### `link:prepare("SELECT $1 AS a, $2 AS b"):execute(1, 'string_value') -- or link:prepare("SELECT $1 AS a, $2 AS b")(1, 'string_value')`  
- - - a: 42
      b: "string_value"

Closes database link.

Returns: nil

Writable variables

  • pg.types.null -- convert postgresql NULL to this value (default: nil).
  • link.error -- function called on SQL query failure (default: ``)
  • link.debug -- function called on each SQL query (default: ``) .


All calls to connections API will be serialized, so it should to be safe to use one connection from some count of fibers. But you should understand, that you can have some unwanted behavior across db calls, for example if another fiber ‘injects’ some sql between two your calls.

See Also