2

I have a column named DTUpdated of type timestamp with time zone.

I created a function to automatically update that column with every modification:

CREATE OR REPLACE FUNCTION public."RowModifiedFunction"()
    RETURNS trigger AS $$

BEGIN
    NEW.DTUpdated = clock_timestamp();  
    RETURN NEW;
END;

and apply it with a trigger in that table

CREATE TRIGGER "RowModifiedTrigger"
    BEFORE UPDATE 
    ON public."Departments"
    FOR EACH ROW
    EXECUTE PROCEDURE public."RowModifiedFunction"();

But when I modify a column I get the error:

"Record new has no field dtupdated" (in lowercase).

2 Answers 2

2

Postgresql requires "these quotes" on any name that contains uppercase.

CREATE OR REPLACE FUNCTION public."RowModifiedFunction"()
    RETURNS trigger AS $$

BEGIN
    NEW."DTUpdated" = clock_timestamp();  
    RETURN NEW;
END;
Sign up to request clarification or add additional context in comments.

1 Comment

it's best to just use lowercase for everything, then you don't need quotes :)
0

if you column is case sensitive, use double quotes:

NEW."DTUpdated" = clock_timestamp();  

NB: usually setting default value to now() instead of such trigger. The only case you need trigger if you want it to fire on specific modifications only

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.