V
V
vladlvl2017-09-17 11:47:39
PostgreSQL
vladlvl, 2017-09-17 11:47:39

PostgreSQL 9.4.9. Text column: some values ​​were added as string, others as integer - can this result in NULL values?

Full question: Some cars appear as null in the 'car_id' column. Initially, all fields under the 'car_id' column had values, but some values ​​were added as integer ('car_id: 1') and others as string ('car_id: ' 1'') Why is this important
SQL:
CREATE TABLE garage.users
(
car_id text COLLATE pg_catalog."default",
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2017-09-17
@melkij

As added, so it will be stored and read.

postgres=# create schema garage;
CREATE SCHEMA
postgres=# CREATE TABLE garage.users
(
car_id text COLLATE pg_catalog."default"
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
CREATE TABLE
postgres=# insert into garage.users values ('1'), ($$'1'$$), (null);
INSERT 0 3
postgres=# select car_id, car_id is null from garage.users ;
 car_id | ?column? 
--------+----------
 1      | f
 '1'    | f
        | t

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question