11 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
Turso Agent
35e6735d47 fix CI failure 2026-10-12 19:40:15 +00: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
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
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