Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8840481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:28:28+00:00 2026-06-14T10:28:28+00:00

Brand new to python and loving it, and I imagine this might be a

  • 0

Brand new to python and loving it, and I imagine this might be a simple one.
I am currently inserting points into SQL Server 2008 via a Python script with the help of pymssql.

var1 = "hi"
lat = "55.92"
lon = "-3.29"

cursor.execute("INSERT INTO table (field1, x, y) VALUES(%s, %s, %s)", 
(var1 , lat, lon))

This all works fine.
I need to also insert those coordinates into a GEOGRAPHY type field (called geog).

geog_type = "geography::STGeomFromText('POINT(%s %s)',4326))" % (lat, lon)

cursor.execute("INSERT INTO table (field1, x, y, geog) VALUES(%s, %s, %s, %s)", 
(var1 , lat, lon, geog_type))

This throws the following exception:

The label geography::STGeomFro in the input well-known text (WKT) is
not valid. Valid labels are POINT, LINESTRING, POLYGON, MULTIPOINT,
MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION, CIRCULARSTRING,
COMPOUNDCURVE, CURVEPOLYGON and FULLGLOBE (geography Data Type only).

From SSMS I can run an insert statement on the table to insert a point fine.

USE [nosde]
INSERT INTO tweets (geog) 
    VALUES(
        geography::STGeomFromText(
        'POINT(55.9271035250276 -3.29431266523898)',4326))

Let me know in the comments if you need more details.

Some of my workings on pastebin.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:28:29+00:00Added an answer on June 14, 2026 at 10:28 am

    Several issues – firstly, you’re supplying the coordinates in the wrong order – the STPointFromText() method expects longitude first, then latitude.

    Secondly, it may be easier to use the Point() method rather than the STPointFromText() method, which doesn’t require any string manipulation – just supply the two numeric coordinate parameters directly. http://technet.microsoft.com/en-us/library/bb933811.aspx

    But, from the error message, it appears that the value you’re sending is attempting to be parsed as a WKT string. If this is the case, you don’t want the extra geography::STGeomFromText and the SRID at the end anyway – these are assumed. So try just supplying:

    geog_type = "'POINT(%s %s)'" % (lon, lat)
    
    cursor.execute("INSERT INTO table (field1, x, y, geog) VALUES(%s, %s, %s, %s)", 
    (var1 , lat, lon, geog_type))
    

    I’m not sure if you need the extra single quotes in the first line or not, but don’t have a system to test on at the moment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Brand new to Python (and programming in general), if this is simple and/or answered
I'm brand new to python, and need some help understanding this code fragment: for
I'm brand new to Django, so the answer to this is probably very simple.
Im brand new to python and SQL, but enjoying the learning curve. I am
I'm brand new at Python and I'm trying to write an extension to an
I'm brand new to Python and trying to learn it by replicating the following
I am brand new to Python and am trying to write a monitor to
Python 2.5.4. Fairly new to Python, brand new to decorators as of last night.
I'm brand new to Eclipse (learning Python). I'm really confused about the terminology within
brand new on this forum and this is my first post! At work we're

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.