6

How to set a default value for Point column on MYSQL table

I tried

`location` POINT NULL DEFAULT POINT(7.0, 81.0),

but gives an error

ERROR: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'POINT(7.0, 81.0),

How to set default value to Point Column

1 Answer 1

4

A column with type POINT cannot have a default value.

if you run create table x(locationPOINT not null DEFAULT 7.0, 81.0) you will see the message

BLOB/TEXT column 'location' can't have a default value

You can refer to this page

4
  • Thanks for the reply.Is there any reference on this.I found informit.com/articles/article.aspx?p=1238838&seqNum=2 Which was written on 2008 Commented Apr 21, 2015 at 7:55
  • 3
    I can't add a special index if there is no default value! so what's wrong?
    – AiShiguang
    Commented Nov 28, 2016 at 10:36
  • 1
    I'm running into this problem and I haven't found any solution other than to make sure I specify a value myself. I.e. in any code written in another language that interfaces with the database and creates an entry in the appropriate table, I have the code insert the desired default value manually. It feels like a "hack" or poor solution, and I wish default values for points were implemented, but it works.
    – cazort
    Commented Apr 19, 2017 at 19:32
  • Alternatively, MariaDB (from v. 10.2.1 onward) supports defaults for BLOB/TEXT columns, and is (mostly) backwards compatible with MySQL.
    – cazort
    Commented Apr 19, 2017 at 19:34

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.