22 Commits

Author SHA1 Message Date
Sebastien Tardif
f3309d06f4 postgres: disable load_extension on the wire listener
tursopg --server reused DatabaseOpts::turso_cli(), which turns on SQL
load_extension. The listener has no password (NoopHandler). A client
could SELECT load_extension and run native code in the server process.

Interactive CLI still enables the flag. The wire path uses the library
default (off), matching sqlite3_enable_load_extension and #3250.

Tests: tursopg wire_load_extension_is_disabled,
       repl_load_extension_still_attempts_to_open_the_file
Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
2026-10-15 08:16:48 +03:00
Pedro Muniz
50e44b4c8c Merge 'postgres: report boolean catalog column types' from Pedro Muniz
Part 2 of 22 in the pg_dump feature series, stacked on
https://github.com/tursodatabase/turso/pull/9716 (`postgres-pgdump-
catalog-tableoid`). Review this diff against its immediate parent.

Declare existing catalog boolean fields as BOOLEAN instead of INTEGER,
so PostgreSQL clients receive the expected column types. Stored row
values remain unchanged. tableoid comes from the preceding layer.

This is one of ten smaller layers extracted from the former combined PR
#9701. Catalog system columns and boolean types now come before session
setup. The combined source and existing regression tests are unchanged;
early layers do not claim complete pg_dump support.

Reorganized with Amp under Pedro's direction, preserving the published
combined source and running before/after regressions plus cumulative
checks at every new layer.

Closes #9717
2026-10-13 13:54:24 -03:00
Amp
33aeddbd23 postgres: implement set_config with connection-local state
pg_dump sets search_path to an empty string before reading catalogs. Store
search_path in the injected connection state so native set_config calls
and SET statements update the same session setting during execution.
Keep an explicitly empty path distinct from the default and preserve
access to qualified public tables and implicit PostgreSQL catalogs.

Support session-scoped search_path only. Reject transaction-local settings
and unsupported parameters; transaction rollback restoration and separate
wire-client sessions are not implemented in this change.

Tests: eight new WAL/MVCC regression cases fail before and pass afterward;
424 PostgreSQL integration, 22 frontend, 181 parser, and four wire-protocol
search-path tests pass. CLI build and formatting checks pass.

Amp-Thread-ID: https://ampcode.com/threads/T-01a11786-6662-751d-925e-4ec4fecf16b3
Co-authored-by: pedro muniz <pedro.muniz.carlo@gmail.com>
2026-10-12 22:51:23 +00:00
Turso Agent
35e6735d47 fix CI failure 2026-10-12 19:40:15 +00:00
Pekka Enberg
4de24b0c62 core: Pass connection settings to Database::connect as ConnectOpts
Database had five public ways to open a connection: connect,
connect_with_encryption, connect_with_page_codec, connect_async and
connect_with_encryption_async. Every new connection setting needs more
variants, and the async path doubles them again.

Database::connect and Database::connect_async now take a ConnectOpts
that holds the encryption key and the page codec, and the other three
variants are removed. ConnectOpts has no Default, so every caller goes
through ConnectOpts::new() and a required argument added there later
makes the compiler find every call site.
2026-10-12 10:05:12 +03:00
Joe
6a389d2261 postgres: support new exit commands for tursopg cli 2026-08-27 23:54:16 -07:00
Joe
eee85471e7 postgres: document pg_get_expr support 2026-08-12 21:48:54 -07:00
Joe
9c317f6723 postgres: add more conformance tests for pg_get_expr 2026-08-12 21:48:54 -07:00
themixednuts
31e1019d9b cli: detect Windows terminal themes
Query terminal background colors on Windows and fall back to the native console color table when ANSI responses are unavailable. Share color parsing across platforms, bound terminal reads, and restore console modes after detection. Cache the detected theme for the process so repeated lookups do not re-query the terminal.

Tests: cargo test --locked -p turso_cli config::terminal::tests -j1; cargo check --locked -p tursopg --tests
2026-08-11 05:07:30 -05:00
themixednuts
5ab2eda1ff cli: preserve platform paths in dot commands
Tokenize dot commands without treating path separators as shell escapes, and share the same parser between execution and completion. Keep quoted paths and embedded quotes intact across the Turso and PostgreSQL CLIs.

Tests: cargo test --locked -p turso_cli; cargo check --locked -p tursopg --tests
2026-08-11 05:07:30 -05:00
Mikaël Francoeur
a90d1c806e Merge 'Pg search path resolution' from
Adds PostgreSQL frontend support for `SET search_path` when resolving
unqualified table names.
The change stores `search_path` as PostgreSQL session state, passes it
into statement preparation, and makes table resolution honor the
configured schema order. Explicitly qualified names keep their existing
behavior. The resolver also preserves temp-schema priority and maps
`public` to the main database.
This also updates the PostgreSQL SET parser helper to support multi-
value `search_path` assignments and adds regression coverage for the new
behavior.
`SET search_path` was already accepted by the PostgreSQL parser, but it
did not affect name resolution. As a result, queries like `SELECT * FROM
demo` could resolve to whichever attached schema happened to be
found first instead of following PostgreSQL search path semantics.
This makes the PostgreSQL frontend behave closer to Postgres for schema-
qualified and unqualified table lookup, especially when multiple schemas
contain tables with the same name.
Related to the PostgreSQL frontend TODO for `SET search_path`.
I used AI for codebase navigation, debugging guidance, and review of the
implementation approach and tests. The implementation itself was written
and reviewed by me

Reviewed-by: Mikaël Francoeur (@LeMikaelF)
Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #8062
2026-08-04 17:23:18 -04:00
Pekka Enberg
100efe6bfc Merge 'postgres/cli: auto-attach persisted schemas on startup' from
Auto-attaches persisted PostgreSQL schema sidecar databases during
tursopg startup.
`CREATE SCHEMA` stores non-public schemas as sidecar database files.
This change runs the existing schema auto-attach step before dispatching
to server, one-shot SQL, stdin, or interactive CLI modes, so schema-
qualified queries continue to work after reopening the main database.
Adds a CLI regression test that creates a schema/table in one tursopg
process and reads it back from a second process using the same file-
backed database.
Before this change, sidecar schema files persisted on disk, but the
regular CLI startup path did not reattach them. Reopening the main
database and querying `schema.table` failed with `no such database`
until `CREATE SCHEMA` was run again.
This makes persisted schema behavior consistent across tursopg startup
modes.
I used AI for codebase navigation, debugging guidance, and review of the
implementation approach and tests. The implementation itself was written
and reviewed by me

Reviewed-by: Mikaël Francoeur (@LeMikaelF)

Closes #8084
2026-08-03 12:22:06 +03:00
haze518
51d2b78624 update postgres todo file 2026-07-31 16:39:38 -04:00
theFestest
1148fd68a0 postgres/cli: add wire test pinning version() to server_version
The version() string and the server_version startup parameter are
hardcoded independently (SERVER_VERSION in the frontend, pgwire's
DefaultServerParameterProvider default), so a pgwire upgrade could
silently drift the two apart. Compare their numeric prefixes over one
connection: the harness now keeps the startup response and can extract
ParameterStatus and DataRow values.
2026-07-30 19:26:53 -04:00
theFestest
e9ac51bd6d postgres: implement session information functions
Adds version(), current_database(), current_schema(), pg_backend_pid(),
quote_ident(), quote_literal(), and NULL stubs for
obj_description()/col_description() to the frontend dialect. The bare
current_schema and current_catalog keywords translate to the same
functions. Zero-argument session functions in FROM position desugar
into a one-row subselect (cast to TEXT because bare subselect columns
wire as bytea) since core's TableCall path resolves only table-valued
functions.

Result columns without an explicit alias are now named after the
function or keyword as PostgreSQL derives them (FigureColname). This
also fixes count(*) reporting as "count (*)" instead of "count".

quote_ident classifies keywords with pg_query's scanner, so reserved
keywords quote and unreserved ones stay bare. version() reports the
same major version as the server_version startup parameter pgwire
advertises.

Tests: postgres/tests/integration/postgres/functions.rs;
pg-sqltests/functions.sqltest validated case-by-case against stock
PostgreSQL 16.
2026-07-30 19:26:53 -04:00
haze518
a4aff886c7 postgres/cli: auto-attach persisted schemas on startup 2026-07-29 09:04:23 +06:00
Pekka Enberg
8f8061a5c5 cli: switch syntect back to crates.io release
The git pin (rev 64644ffe, added in June 2025 for the onig/GCC 15 build
fix) forces cargo to clone syntect with its testdata/Packages submodule,
so CI randomly fails whenever fetching sublimehq/Packages flakes.

syntect 5.3.0 on crates.io contains the pinned rev (v5.3.0 is 36 commits
ahead of it, 0 behind) and ships as a self-contained tarball, so the git
clone and submodule fetch disappear entirely. Applies to both tursodb
and tursopg, dependencies and build-dependencies alike.

Tests: cargo build -p turso_cli -p tursopg; tursodb answers queries.
2026-07-28 14:15:51 +03:00
roboturso
db964725a9 postgres: support CREATE TABLE AS and SELECT INTO
Translate PostgreSQL CREATE TABLE AS and its legacy SELECT ... INTO
spelling into Turso's CREATE TABLE ... AS SELECT so the pg frontend can
create tables from query results. WITH NO DATA creates the table from
the SELECT's shape without copying rows, IF NOT EXISTS is honored, and
INTO in nested or compound positions is rejected rather than silently
dropped. The server reports completion as `SELECT n` like PostgreSQL,
except WITH NO DATA which keeps the plain CREATE TABLE AS tag.

Explicit column lists on CTAS are rejected because the engine derives
column names from the SELECT and cannot override them.

Tests: postgres/conformance/pg-sqltests/table.sqltest covers CTAS and
SELECT INTO behavior; postgres/cli/tests/tursopg.rs covers the wire
command tags; postgres/tests/integration covers the rejection paths
where Turso intentionally diverges from PostgreSQL.

Co-authored-by: theFestest <theFestest@users.noreply.github.com>
2026-07-26 21:58:00 +03:00
Rajat Venkatesh
3fb5a5b184 postgres: accept COMMENT ON as a no-op
Allow PostgreSQL clients and migrations to issue COMMENT ON statements without persisting comment metadata. Return the COMMENT wire completion tag so clients do not observe the internal no-op statement.

Tests: cargo fmt --all -- --check; git diff --check
2026-07-17 20:38:10 +05:30
Pekka Enberg
1f8b725dd0 postgres/cli: fix port collisions in wire-protocol tests
The wire-protocol tests derived their server port from a fixed per-test
seed plus the test process id. nextest runs each test in its own process
with roughly sequential pids, so two concurrently started tests can
compute the same port. The loser of the bind race has its server exit,
but its readiness poll still succeeds by connecting to the winner's
server — and the test then fails mid-run when the winner tears that
server down. This broke main's macOS build-native job with
wire_cast_reports_target_type returning no RowDescription.

Ask the kernel for a free ephemeral port instead, and treat the child
exiting during the readiness poll as a lost bind race, retrying on a
fresh port rather than connecting to another test's server.

Tests: cargo test -p tursopg --test tursopg
2026-07-16 14:04:42 +03:00
Pekka Enberg
fe076ddd54 postgres/cli: rename pgmicro command to tursopg
Name the PostgreSQL-compatible CLI after the product, consistent with
tursodb and the turso_pg* crate naming. The prompt, history file, crate
and binary names, tests, and documentation all follow.
2026-07-16 12:40:03 +03:00
Glauber Costa
52003e04e1 postgres/cli: add pgmicro CLI
Interactive PostgreSQL-flavored shell (psql-style commands, multi-line
editing via a read state machine) that embeds the PG frontend and can
serve the pgwire protocol via turso_postgres_server.

Tests: postgres/cli/tests/pgmicro.rs

Co-authored-by: Pekka Enberg <penberg@iki.fi>
2026-07-16 12:40:03 +03:00