function

Custom error message for Postgresql CHECK IN list constraint

冷暖自知 提交于 2020-07-19 23:07:22
问题 I would like to create a more specific error message for Postgres CHECK IN violations. So for example a violation of the following CHECK constraint on a column: management_zone varchar(15) NOT NULL CHECK (management_zone IN ('Marine', 'Terrestrial') ), should return a custom error message such as ie.: "Hint: Check spelling. Only allowed inputs are: 'Marine', 'Terrestrial'. The best solution I have seen so far solves it by using the error message as the name of the check constraint, ie ADD

Is there a way to create an R function using a string formula with ', and “ =~”?

一曲冷凌霜 提交于 2020-07-19 18:07:24
问题 I'm trying to create an R function that lets me specify latent variables and indicators. Is there a way to convert the following three code lines into a function? ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' I tried using paste and paste0 but it didn't work very well. For example, using just one latent variable, I tried this: myFunction <- function(z, x, ...) { latent_variable <- paste0(x) latent_indicators <- paste0(..., collapse = " + ") latent_formula <- paste0(

how variables are stored and treated in recursion function in python?

牧云@^-^@ 提交于 2020-07-19 04:02:33
问题 I am quite confused with the code below. def a(x): print(x) if x > 0: a(x - 1) print(x) #I am confused with this print statement a(5) The above code outputs: 5 4 3 2 1 0 0 1 2 3 4 5 Up till the 0 I understand how it prints, but then why it prints in ascending order . Variable x is changing so what I thought the output would be is the last assigned value of x that is 0 . My predicted output: 5 4 3 2 1 0 0 0 0 0 0 0 So how does it track the value of x...? Can someone explain in brief what

How can i put a delay with C#?

允我心安 提交于 2020-07-18 14:25:27
问题 I want to make an application to execute several instructions to pass the following instruction has to wait a few milliseconds. Such that: while(true){ send("OK"); wait(100); //or such delay(100); } Is it possible in C#? 回答1: Thread.Sleep(100); will do the trick. This can be found in the System.Threading namespace. 回答2: You can use the Thread.Sleep() method to suspend the current thread for X milliseconds: // Sleep for five seconds System.Threading.Thread.Sleep(5000); 回答3: To sleep for 100ms

Python: Calculate bearing between two lat/long

做~自己de王妃 提交于 2020-07-18 05:59:09
问题 I am attempting to calculate the bearing between two lat/long. I don't have a question regarding the function/formula per se, provided: def get_bearing(lat1, long1, lat2, long2): dLon = (long2 - long1) y = math.sin(dLon) * math.cos(lat2) x = math.cos(lat1) * math.sin(lat2) - math.sin(lat1) * math.cos(lat2) * math.cos(dLon) brng = math.atan2(y, x) brng = np.rad2deg(brng) return brng the problem is that the result isn't what is expected. The intended usage of the function returns the bearing

lambda is slower than function call in python, why

做~自己de王妃 提交于 2020-07-18 04:43:20
问题 I think lambda is faster than function call, but after testing, I find out that I am wrong. Function call is definitely faster than lambda call. Can anybody tell me why? And how to speed up function call in Python? I'm using Ubuntu 14.04 and Python 2.7.6 >>> timeit('def a():return 222*333 ;a()') 0.08195090293884277 >>> timeit('a=lambda:222*333 ;a()') 0.11071300506591797 >>> timeit('a=lambda: [].extend(range(10)) ;a()') 0.40241098403930664 >>> timeit('a=lambda: [].extend(range(10)) ;a()') 0

How to create function that returns nothing

二次信任 提交于 2020-07-16 17:01:33
问题 I want to write a function with pl/pgsql . I'm using PostgresEnterprise Manager v3 and using shell to make a function, but in the shell I must define return type. If I don't define the return type, I'm not able to create a function. How can create a function without return result, i.e a Function that creates a new table? 回答1: Use RETURNS void like below: CREATE FUNCTION stamp_user(id int, comment text) RETURNS void AS $$ #variable_conflict use_variable DECLARE curtime timestamp := now();

What is the syntax for using the restrict keyword for a 2d array function parameter?

喜夏-厌秋 提交于 2020-07-16 08:21:12
问题 I have an array declared in my main function: float A[n][n]; My goal is to pass it to a function with the restrict keyword: void func(int n, float restrict A[][n]) I tried the syntax above, but I am not getting the optimization in running time that I am expecting. I have also seen this syntax for 1d arrays: void func(int n, float A[restrict]) 回答1: The pointer can be restrict. All below forms are equivalent: void func(int n, float A[restrict n][n]); void func(int n, float A[restrict][n]); void

What is the syntax for using the restrict keyword for a 2d array function parameter?

折月煮酒 提交于 2020-07-16 08:21:08
问题 I have an array declared in my main function: float A[n][n]; My goal is to pass it to a function with the restrict keyword: void func(int n, float restrict A[][n]) I tried the syntax above, but I am not getting the optimization in running time that I am expecting. I have also seen this syntax for 1d arrays: void func(int n, float A[restrict]) 回答1: The pointer can be restrict. All below forms are equivalent: void func(int n, float A[restrict n][n]); void func(int n, float A[restrict][n]); void

How to return a class instance in member function of a class?

℡╲_俬逩灬. 提交于 2020-07-11 05:14:36
问题 I want to return a class instance in member function of a class, my code is: class MyClass(object): def __init__(self, *args, **kwargs): [snippet] def func(self, *args, **kwargs): [snippet] return class_instnace_of_MyClass if __name__ == '__main__': obj = MyClass(...) newobj = obj.func(...) # type(newobj) is MyClass I think I can call __init__() in func() , and return a new instance of MyClass, but I don't think it is a Pythonic way to do so. How should I do that? Thank you! 回答1: I feel like