skip to Main Content

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


  1. Like the function name implies, ST_GeomFromText() takes text input. The first parameter needs to be a single (concatenated) string in valid format.

    Either concatenate and pass a single parameter:

    SELECT ST_GeomFromText('POINT(127.058923 37.242621)', 4326);
    

    Translates to:

    SELECT ST_GeomFromText(${point}, 4326);
    

    Or let Postgres concatenate longitude & latitude for you:

    SELECT ST_GeomFromText(format('POINT(%s %s)', '127.058923', '37.242621'), 4326)
    

    Translates to:

    SELECT ST_GeomFromText(format('POINT(%s %s)', ${longitude}, ${latitude}), 4326)
    

    There are various ways to concatenate in Postgres:

    Related:

    Login or Signup to reply.
  2. You cannot have parameters inside a string constant.

    Try using

    ST_SetSRID(ST_MakePoint(${longitude}, ${latitude}), 4326)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search