Skip to content

Fixes copy from#8

Merged
glommer merged 12 commits into
masterfrom
fixes-copy-from
Apr 18, 2026
Merged

Fixes copy from#8
glommer merged 12 commits into
masterfrom
fixes-copy-from

Conversation

@glommer

@glommer glommer commented Apr 18, 2026

Copy link
Copy Markdown
Owner

many fixes trying to run the postgres regression test suite.

Most notable are COPY FROM - which is used almost everywhere, and a virtual table where we can check for errors.

glommer and others added 12 commits April 18, 2026 06:59
Add support for COPY table FROM file with PostgreSQL default text
format (tab-delimited). This is the prerequisite for running PG
regression tests that load data via COPY.

- Add AST types: Stmt::Copy, CopyDirection, CopyTarget, CopyFormat
- Add PG translator: translate_copy() and try_extract_copy_from()
- Add text format parser in core/copy.rs with backslash escape handling
- Add COPY FROM handler in pg_dispatch.rs using prepare/bind/step
- Supports column subsets, HEADER option, custom delimiter, custom NULL
- Wraps inserts in a transaction for atomicity
- Wire protocol returns COPY N matching PostgreSQL behavior

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The PG translator was baking type parameters into the type name string
(e.g. varchar(4)) instead of setting the AST Type.size field. This
caused Turso custom type validation to reject parametric types like
varchar(4) and numeric(10,2) as unknown datatype on STRICT tables.

Fix both translate_create_table_column (CREATE TABLE) and
translate_column_def (ALTER TABLE) to populate Type.size from the
new PgTypeMapping.type_params field.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
translate_binary_expr assumed all AExprKind::AexprOp expressions were
binary, failing with Missing left expression on unary operators like
+42. PostgreSQL parses these as A_Expr with only rexpr set.

Detect the unary case (no lexpr) and map to the appropriate
ast::UnaryOperator variant.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
SELECT i.* FROM table i was failing with 'no such column: i' because
the ColumnRef [String('i'), AStar] was not recognized as a table-star
pattern. The translator only checked if the first field was AStar
(for bare *) but not the last field (for table.*).

Now correctly emits ResultColumn::TableStar for qualified star refs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add handling for standalone VALUES statements (VALUES (1,'a'), (2,'b'))
by detecting SelectStmt with values_lists and no target_list, producing
OneSelect::Values AST nodes.

Also add RangeSubselect to the comma-join FROM item handler, which was
missing (only the first FROM item handled subselects).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
In PG, float8(x) is equivalent to CAST(x AS float8). Map these
function calls to Expr::Cast in the translator instead of passing
them as unknown functions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
These functions are used in PG regression tests (int4, int8, boolean).
- gcd/lcm: greatest common divisor / least common multiple
- repeat: repeat a string N times
- to_char: basic numeric formatting with PG format patterns
- pg_input_is_valid: validate text input for a given type

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
gcd(INT_MIN, 0) would panic on .abs(). Use wrapping_abs and return
an error string for overflow cases, matching PG behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
DELETE FROM t AS dt WHERE dt.a > 75 failed because the alias was
not set on the QualifiedName. This also benefits UPDATE aliases.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PG internal functions for boolean equality/inequality, used in the
boolean regression test suite.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds pg_input_error_info(input, type) as a virtual table that returns
error details when input text is invalid for a given type. Returns one
row with (message, detail, hint, sql_error_code) — all NULL if valid,
populated with PG-compatible error messages if invalid. Supports bool,
int2/int4/int8, float4/float8, and text types.

This fixes the last remaining error in the PG boolean regression test
and resolves pg_input_error_info errors in int4 and int8 tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The REPL tokenizer now recognizes PostgreSQL dollar-quoted strings
($$...$$, $body$...$body$, etc.) so that semicolons inside function
bodies don't prematurely terminate the statement.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@glommer glommer merged commit 5af0043 into master Apr 18, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant