Skip to main content

PostgreSQL (standard.postgresql)

Concept Mapping

UQALPostgreSQL
TableTable or View
RowRow
FieldColumn
get_tableSELECT … FROM
get_rowSELECT … LIMIT 1
get_valueSELECT field … LIMIT 1
insert_rowINSERT INTO … VALUES
updateUPDATE … SET
deleteDELETE FROM
create_viewCREATE OR REPLACE VIEW
Native escapedb.sql("…")

Connection Setup

uqal add-connection mydb standard.postgresql \
--host localhost \
--port 5432 \
--database mydb \
--secret user myuser \
--secret password mypassword \
--no-interactive

Options available in uqal_config.json:

KeyDefaultDescription
hostlocalhostPostgreSQL server host
port5432PostgreSQL server port
databaseDatabase name
options.sslmodepreferSSL mode (disable, require, …)
options.connect_timeout10Connection timeout in seconds

Type Mapping

UQAL Core TypePostgreSQL Type
intINTEGER
floatDOUBLE PRECISION
varcharVARCHAR
boolBOOLEAN
dateDATE
datetimeTIMESTAMP WITH TIME ZONE
jsonJSONB
uuidUUID

Schema Discovery

UQAL discovers your schema by reading PostgreSQL's information_schema:

  • Tables from information_schema.tables
  • Columns and types from information_schema.columns
  • Views are included automatically — they appear as regular tables in UQAL

After a sync_schema, any view in your database is queryable like a table:

mydb.active_orders.get_table()

Views

create_view translates to a CREATE OR REPLACE VIEW in PostgreSQL:

mydb.create_view active_orders:
let o = table orders where active = true
return o.id, o.customer, o.total

Generates:

CREATE OR REPLACE VIEW active_orders AS
SELECT o.id, o.customer, o.total
FROM orders o
WHERE o.active = true

After the next sync_schema, the view is available for querying.

Native SQL

mydb.sql("SELECT id, name, SUM(total) AS revenue FROM orders GROUP BY id, name ORDER BY revenue DESC")

Blocked patterns (security validator):

  • DROP TABLE / DROP DATABASE
  • TRUNCATE
  • CREATE USER / ALTER USER
  • GRANT / REVOKE

Safe DDL like CREATE TABLE and CREATE INDEX passes through unless explicitly blocked in your configuration.

Example

# Connect
uqal add-connection hrdb standard.postgresql --host db.example.com --database hr

# Sync schema
uqal run "hrdb.sync_schema"

# Query employees
uqal run "hrdb.employees.get_table(where department = 'Engineering', fields id, name, salary)"

# Create a view
uqal run "hrdb.create_view senior_engineers:
let e = table employees where department = 'Engineering' and years_experience >= 5
return e.id AS employee_id, e.name, e.salary"

# Query the view
uqal run "hrdb.senior_engineers.get_table()"