Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when to use = and := in postgreSQL?

Im using plpgsql to write triggers n Im wondering when to use = and when to use := in postgreSQL, what is the difference???

for example:

CREATE OR REPLACE FUNCTION on_ai_myTable() RETURNS TRIGGER AS $$
DECLARE
t_ix real;
n int;

BEGIN
IF NEW.time_type = 'Start' THEN
    SELECT t.time_index FROM table_ebscb_spa_log02 t WHERE t.fn_name = NEW.fn_name AND t.time_type = 'Start' ORDER BY t.timestamp02 DESC LIMIT 1 INTO t_ix;
      GET DIAGNOSTICS n = ROW_COUNT;
        IF (n = 0) THEN 
        t_ix = 1;
        ELSE 
        t_ix = t_ix + 1;
        END IF;
END IF;
NEW.time_index = t_ix;
return NEW;
END
$$
LANGUAGE plpgsql;
like image 559
Natysiu16 Avatar asked Jan 09 '23 02:01

Natysiu16


1 Answers

In version 9.4, the documentation was updated to make it clear that there is no difference.

Version 9.4:

40.5.1. Assignment

An assignment of a value to a PL/pgSQL variable is written as:

variable { := | = } expression;

[...]

Equal (=) can be used instead of PL/SQL-compliant :=

In previous versions, := alone was mentioned as the assignment operator, but = has been working since the beginning.

like image 190
Daniel Vérité Avatar answered Jan 14 '23 21:01

Daniel Vérité