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>
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
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.
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.
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>
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
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
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.
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>