1

I have this (non working) query:

"INSERT INTO notes (
         lat, 
         lng, 
         point)
      VALUES (
         :lat,
         :lng,
         ST_GeometryFromText('POINT(:lat :lng)'))"

Which I am running against this table:

CREATE TABLE notes
(
  id serial NOT NULL,
  lat real NOT NULL,
  lng real NOT NULL,
  point point NOT NULL,
  CONSTRAINT notes_pkey PRIMARY KEY (id )
)

The query is prepared with PDO (php) but that is not the point I think. The result I get back is an exception claiming that:

SQLSTATE[42804]: Datatype mismatch: 7 ERROR:  column "point" is of type point but expression is of type geometry
LINE 8:          $8, $9, $10, $11, $12, ST_GeometryFromText('POINT(:...
                                        ^
HINT:  You will need to rewrite or cast the expression.

How can I cast the expression as suggested?

0

2 Answers 2

1

Looks like you are using the standard Postgres type point:

"INSERT INTO notes (lat, lng, point)
 VALUES (:lat, :lng, '(:lat, :lng)'::point)"

You may want to use the PostGis type geometry in your table instead.

Sign up to request clarification or add additional context in comments.

2 Comments

Oh so when I do CREATE EXTENSION postgis; new data types are added?
@nourdine: Yes. Lots of new types and functions and other stuff.
0

It's not clear if you want to use PostgreSQL's point type, or PostGIS's geometry type. If it is the later, this answer should help out.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.