What differences exist between the different ways of defining a DEFAULT 0?

3

I have the following query:

ALTER TABLE compras.factura_gasto ADD COLUMN m_excento numeric(36,2);
ALTER TABLE compras.factura_gasto ALTER COLUMN m_excento SET DEFAULT 0::numeric;

My question is: In SET DEFAULT Is there any difference between having SET DEFAULT 0 and SET DEFAULT 0::numeric ?

    
asked by Kinafune 09.10.2018 в 06:38
source

1 answer

3

No significant difference. Particularly the notation 0::numeric is an explicit "cast" of a literal, which in itself is already considered numerical, it might make more sense to do '0'::numeric , but in any case what is always worth is the definition of the column, in your case numeric(36,2) , so the engine will try to "cast" any value to that type of data, with any of these forms the result is the same:

ALTER TABLE dummy ALTER COLUMN m_excento SET DEFAULT 0
ALTER TABLE dummy ALTER COLUMN m_excento SET DEFAULT '0'
ALTER TABLE dummy ALTER COLUMN m_excento SET DEFAULT '0'::numeric
    
answered by 09.10.2018 / 21:17
source