What Happens When You Add NULL And Integer

Question

What happens when you add a NULL value and an integer?

Answer

You get an error.

-- Drop table if exists
DROP TABLE IF EXISTS names;

-- Create table called names
CREATE TABLE names (
    -- string variable
    name varchar(255),
    -- integer variable
    score int
)

-- Insert into the table
INSERT INTO names (name, score)
-- two rows
VALUES
    (NULL, 1),
    ('Tommy', 1)

-- Add a column with a NULL value and a integer
SELECT
    name + score as results
FROM names

[42883] ERROR: operator does not exist: character varying + integer Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts. Position: 17