Hello I am using postgres 12. I've been learning for a few days now.
I wanted to know if it's possible to write into the CREATE TABLE stage: IF column_x is NULL, return 'alternative value'
?
This is my current table:
CREATE OR REPLACE FUNCTION update_modified_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.modified = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TABLE example (
id BIGSERIAL NOT NULL PRIMARY KEY,
entry_name VARCHAR(150) NOT NULL UNIQUE,
about VARCHAR(1500),
org_type VARCHAR(150),
category VARCHAR(150),
sub_categories VARCHAR(300),
website_link VARCHAR(300) UNIQUE,
membership VARCHAR(100),
instagram VARCHAR(150) UNIQUE,
twitter VARCHAR(150) UNIQUE,
link_lists VARCHAR(100) UNIQUE,
facebook VARCHAR(200) UNIQUE,
youtube VARCHAR(200) UNIQUE,
podcast VARCHAR(200) UNIQUE,
tags VARCHAR(150),
created TIMESTAMPTZ NOT NULL DEFAULT NOW(),
modified TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE TRIGGER set_timestamp BEFORE UPDATE ON bbdb FOR EACH ROW EXECUTE PROCEDURE update_modified_column();
So in this scenario, I would like for any null entries in 'about' and 'website_link' to say 'Coming soon' and all the social media null entries to just say 'None'. I guess my UNIQUE constraint would not allow this? (I have them to avoid duplicates of entries in case the 'entry_name' is submitted with variations).
Thanks for any help.