3

So here is my problem,

I have a procedure with :

    DECLARE
serialvar INTEGER;

BEGIN
serialvar := NEW.battery_serial;

CREATE OR REPLACE VIEW battery_vue
AS
SELECT * FROM cells WHERE battery_serial = serialvar;
RETURN NEW;
END;

but when the trigger of that procedure is activated i have an error saying :

ERROR: the column « serialvar » does not exist

LINE 3: SELECT * FROM cells WHERE battery_serial = serialVar

1
  • Maybe you need TEMPORARY VIEW? It will be dropped at the end of session and will not conflict with other sessions. Details here. Commented Dec 7, 2012 at 13:24

1 Answer 1

1

You have to pass the value into a dynamic SQL like

BEGIN

EXECUTE $$CREATE OR REPLACE VIEW battery_vue
AS
SELECT * FROM cells WHERE battery_serial = $$ || NEW.battery_serial;

RETURN NEW;

END;

this way you take the new value, and if it is 1 (for example), then battery_vue will show you only the cells where battery_serial = 1. Is this what you want? (The next insert or whatever will recreate the view, possibly with a different battery_serial.)

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the answer it works !, yes i want the view to show only Battery_serials = 1

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.