PostgreSQL – set a default cell value according to another cell value

This is not possible with a simple DEFAULT value, as the manual clearly states: The value is any variable-free expression (subqueries and cross-references to other columns in the current table are not allowed). You could use a trigger instead: CREATE OR REPLACE FUNCTION trg_foo_b_default() RETURNS trigger LANGUAGE plpgsql AS $func$ BEGIN — For just a … Read more

Difference between mutation, rebinding, copying value, and assignment operator [duplicate]

This is covered in detail in a relatively popular SO question, but I’ll try to explain the issue in your particular context. When your declare your function, the default parameters get evaluated at that moment. It does not refresh every time you call the function. The reason why your functions behave differently is because you … Read more

In Python, can I specify a function argument’s default in terms of other arguments?

As @Ignacio says, you can’t do this. In your latter example, you might have a situation where None is a valid value for arg2. If this is the case, you can use a sentinel value: sentinel = object() def myfunc(arg1, arg2=sentinel): if arg2 is sentinel: arg2 = arg1 print (arg1, arg2) myfunc(“foo”) # Prints ‘foo … Read more