Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
CREATE TABLE location ( id BIGINT UNSIGNED PRIMARY KEY, latlong VECTOR(2) NOT NULL, VECTOR INDEX (latlong) M=16 DISTANCE=cosine ); INSERT INTO location VALUES (1,Vec_FromText('[-33.8651,151.2099]')), (2,Vec_FromText('[-33.8728,151.2056]')), (3,Vec_FromText('[-33.8795,151.2213]')), (4,Vec_FromText('[-33.8607,151.2001]')), (5,Vec_FromText('[-33.8452,151.2154]')), (6,Vec_FromText('[-33.8734,151.2342]')), (7,Vec_FromText('[-33.8871,151.2075]')), (8,Vec_FromText('[-33.8670,151.1953]')), (9,Vec_FromText('[-33.8413,151.1969]')), (10,Vec_FromText('[-33.8568,151.2151]')), (11,Vec_FromText('[-33.8780,151.1914]')), (12,Vec_FromText('[-33.8662,151.2266]')), (13,Vec_FromText('[-33.8583,151.1761]')), (14,Vec_FromText('[-33.8505,151.1978]')), (15,Vec_FromText('[-33.8755,151.2182]')), (16,Vec_FromText('[-33.8632,151.2090]')), (17,Vec_FromText('[-33.8526,151.2107]')), (18,Vec_FromText('[-33.8703,151.1849]')), (19,Vec_FromText('[-33.8439,151.2285]')), (20,Vec_FromText('[-33.8810,151.1988]')); SET @p = Vec_FromText('[-33.8677, 151.2096]'); SELECT id, Vec_ToText(latlong),VEC_DISTANCE_COSINE(latlong, @p) as score FROM location ORDER BY score ASC LIMIT 3;

Stuck with a problem? Got Error? Ask AI support!

Copy Clear