I need to declare a variable timestamp in postgresql but when I try it it gives me syntax error, if someone could give me the code of how to declare and assign value to a variable it would be very helpful, thanks
I need to declare a variable timestamp in postgresql but when I try it it gives me syntax error, if someone could give me the code of how to declare and assign value to a variable it would be very helpful, thanks
To declare a variable is:
CREATE TABLE prueba (
"Fecha" timestamp(6) with time zone
)
To add / register a record:
INSERT INTO prueba VALUES ('2018-09-29 19:10:25-07');
In this way you declare variables:
user_id integer;
quantity numeric(5);
url varchar;
myrow tablename%ROWTYPE;
myfield tablename.columnname%TYPE;
arow RECORD;
If you want to declare a timestamp variable for example in a function in this way, it can help you:
CREATE OR REPLACE FUNCTION test3() RETURNS void
LANGUAGE plpgsql
AS $$
DECLARE
_currenttime timestamp := now();
BEGIN
copy (SELECT * FROM table1 WHERE createdtime < _currenttime - INTERVAL '1 days') TO '/tmp/table1.csv';
END
$$;
To execute the function:
Select test3();
Greetings