1

I have simple json mysql query that looks like:

SELECT json_object(  
  'isCreated', true,
  'active', IF(s.status = 1, true, false),
  ...)
FROM people;

I dont understand why isCreated returns true as expected and active returns 1 when expected to return true

I tried also to run in the mysql shell SELECT IF(1= 1, true, false) and I get back 1, I want it to be true...

2
  • Probably you want to say IF(s.status = 1, 'true', 'false') Commented Jan 1, 2019 at 12:15
  • @Rahul no, that will give me the string 'true' which that is not what i want, i need it fto be true, as boolean, and I said the isCreated works well Commented Jan 1, 2019 at 12:36

1 Answer 1

0

In your case true false are boolean values. MySQL stores boolean values as an integer. If true false were in string format("true","false") it would have returned true or false. Assigning in if condition always treats as true. Please Check below links once.

Sql Docs(Numberic type overview)

sql tutorial

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.