CASE A
SELECT ST_DistanceSphere(
ST_GeomFromText('POINT(127.058923 37.242621)', 4326), "geometryType")as distance FROM "MyTable"
WHERE ST_DistanceSphere(
ST_GeomFromText('POINT(127.058923 37.242621)', 4326), "geometryType") < 500;
CASE B
SELECT ST_DistanceSphere(
ST_GeomFromText('POINT(${longitude} ${latitude})', 4326), "geometryType")as distance FROM "MyTable"
WHERE ST_DistanceSphere(
ST_GeomFromText('POINT(${longitude} ${latitude})', 4326), "geometryType") < 500;
When performing as in A, the query succeeds normally, but when performing as in B, an error of "could not determine data type of parameter $1" occurs.
PostGIS is properly installed in my database.
I’ve tried using both Prisma’s $queryRaw and the Node package postgres, but the issue remains unresolved.
2
Answers
Like the function name implies,
ST_GeomFromText()
takestext
input. The first parameter needs to be a single (concatenated) string in valid format.Either concatenate and pass a single parameter:
Translates to:
Or let Postgres concatenate longitude & latitude for you:
Translates to:
There are various ways to concatenate in Postgres:
Related:
You cannot have parameters inside a string constant.
Try using