Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to substitute variable in postgres?

Hi I am working in Postgres. I have below code

DO $$
DECLARE
    item integer;
begin
    item:=5;
    DROP TABLE IF EXISTS temp_data;
    CREATE temp TABLE temp_data AS
select current_timestamp + interval '1 day' as op;
 
END $$;
select * from temp_data;

In the above code in the Text ‘1 Day’ I would like to replace 1 with variable item. Can someone please help me? Thanks

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you can concat value with item variable

SELECT CURRENT_TIMESTAMP + (item::text || ' day')::interval AS op
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading