Building the table by hand -------------------------- Get High-PM-stars: create table tmp.ppmxHighpm as (select localid, alphaFloat, deltaFloat, pmra, pmDE, RAErr, DecErr, PMRAErr, PMDEErr, Cmag, pm_total, angle_pm from ppmx.data where pm_total>3); For simplicity, we set the region of candidates for geometric lensing to a rectangle, say, 1 arcsec wide around the path PPMX believes the star will take. Since the movements are small, we don't actually work in the tangential plane. We might need to do this later, though. SELECT * FROM ( SELECT ARRAY[ alphaStart+w*sin(a), deltaStart-w*cos(a), alphaEnd+w*sin(a), deltaEnd-w*cos(a), alphaEnd-w*sin(a), deltaEnd+w*cos(a), alphaStart-w*sin(a), deltaStart+w*cos(a)] AS arr FROM ( SELECT 1/3600./2. AS w, alphaFloat+pm_total/3600.*20*cos(angle_pm/180.*3.14159)/cos(deltaFloat/180*3.14159) AS alphaEnd, deltaFloat+pm_total/3600.*20*sin(angle_pm/180.*3.14159) AS deltaEnd, alphaFloat as alphaStart, deltaFloat as deltaStart, angle_pm/180.*3.14159 as a FROM tmp.ppmxHighpm ) AS pos ) AS r, ppmx.data WHERE q3c_poly_query(alphaFloat, deltaFloat, arr);