0

I' learning postgresql, and I typed the following commands.

 CREATE TABLE t(co1 boolean, col2 text);
 INSERT INTO t VALUES(NULL, 'NULL');
 SELECT * FROM t where col2::boolean;

And the result came out like this:

ERROR:  invalid input syntax for type boolean: "NULL".

Why is that happened since things like 'True'::boolean is correct?

5
  • And the error comes from? (CREATE, INSERT or SELECT?) Commented Aug 14, 2018 at 12:14
  • 1
    Now I see, 'NULL' is not the null value, it's a string... Commented Aug 14, 2018 at 12:15
  • 1
    null is neither true nor false Commented Aug 14, 2018 at 12:15
  • What do you trying to achieve ? Commented Aug 14, 2018 at 12:16
  • I tried transforming data from text to boolean. 'True'::boolean has no error, but 'Null'::boolean return an error. Commented Aug 14, 2018 at 12:59

1 Answer 1

2

Your col2 column is text, not boolean

CREATE TABLE t(co1 boolean, col2 text);
 INSERT INTO t VALUES(NULL, 'NULL');
 SELECT * FROM t where col2::text;
Sign up to request clarification or add additional context in comments.

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.