0

Return user id from phone_number

GET_USER_ID = "SELECT user_id FROM user WHERE phone_number = {};"

I am trying to run the above query and got this error :

InternalError: (1366, u"Incorrect integer value: 'SELECT user_id FROM user WHERE phone_number = 0400001122;' for column 'user_id' at row 1")

When i run the query in the mysql workbench, it works fine and returns the correct user_id. I have been researching other posts as well, but most of them are insert problems and a null value for them would fix this in INSERT cases.

However, I am doing a SELECT query.

I have been struggling alot with this error, could anyhow help me out?

Peyman.H
  • 1,819
  • 1
  • 16
  • 26
  • phonenumber type - (varchar(12)PK) user-id type - (int(11) AI PK) – Min Thaw Zin Sep 23 '18 at 11:23
  • read this and set your `sql-mode` https://stackoverflow.com/questions/2536199/1366-incorrect-integer-valuemysql – KC. Sep 23 '18 at 11:27
  • By the way, `VARCHAR(12)` isn't big enough to hold telephone directory numbers. Please read this: https://stackoverflow.com/questions/42255754/phone-number-should-be-a-string-or-some-numeric-type-that-have-capacity-to-save/42255861#42255861 – O. Jones Sep 23 '18 at 11:48
  • 2
    Can you share the output of this query `SHOW CREATE TABLE user `? – Arihant Sep 23 '18 at 11:49
  • Could you share the snippet where this is used? – Mureinik Sep 23 '18 at 11:50
  • I decided to go with different way by passing user_id directly instead of querying through phone number. Not sure why it does not work the other way round. – Min Thaw Zin Sep 23 '18 at 12:14

1 Answers1

0

phone number value is stored in varchar field of mysql table. and it starts with 0, using any number starts with 0 is treated as octal number in python programming language.

kindly make changes in query and pass phone_number value as string in select query, will solve your question.

Sample query as per your input is as:

"SELECT user_id FROM user WHERE phone_number = '0400001122';"

Check this and enjoy coding :) !

Suresh
  • 489
  • 3
  • 7