Learn from the vsql_complex reference implementation using the VEF SDK
The vsql_complex extension is VillageSQL’s reference implementation for custom types using the VEF SDK—demonstrating production-ready extension patterns.Source:villagesql/examples/vsql_complex/ in VillageSQL repository
COMPLEX type for complex numbers (a + bi) with arithmetic, utilities, and aggregation.Usage Example:
Copy
Ask AI
INSTALL EXTENSION vsql_complex;CREATE TABLE signals ( id INT PRIMARY KEY, impedance COMPLEX);INSERT INTO signals VALUES (1, '(50.0,10.0)');SELECT complex_real(impedance) as resistance, complex_imag(impedance) as reactance, complex_abs(impedance) as magnitudeFROM signals;
{ "name": "vsql_complex", "version": "0.0.1", "description": "Complex number data type for VillageSQL", "author": "VillageSQL Contributors", "license": "GPL-2.0"}
VillageSQL supports SELECT INTO OUTFILE and LOAD DATA INFILE for custom types, allowing you to export and import data while preserving custom type values.
Custom types serialize to their string representation when exported:
Copy
Ask AI
INSTALL EXTENSION vsql_complex;-- Create table with custom typeCREATE TABLE signals ( id INT PRIMARY KEY, reading COMPLEX);INSERT INTO signals VALUES (1, '(3.0,4.0)'), (2, '(5.0,12.0)'), (3, '(-1.0,2.0)');-- Export to fileSELECT * FROM signals INTO OUTFILE '/tmp/signals_export.txt';
-- Create new table with same schemaCREATE TABLE signals_imported ( id INT PRIMARY KEY, reading COMPLEX);-- Import dataLOAD DATA INFILE '/tmp/signals_export.txt' INTO TABLE signals_imported;-- VerifySELECT * FROM signals_imported;
SELECT id, reading, complex_abs(reading) AS magnitude, complex_real(reading) AS real_part, complex_imag(reading) AS imag_partINTO OUTFILE '/tmp/signals_computed.txt'FROM signals;
Custom types are exported in their string representation format. Binary export with SELECT INTO DUMPFILE is not currently supported for custom types.