Function executes faster without STRICT modifier?

Maybe an overhead from the repeated function call that is streamlined away by inlining the function? That’s what I’d guess. You’ve got a very simple expression there. An actual function-call presumably involves stack setup, passing parameters etc. The test below gives run-times of 5ms for inlined and 50ms for strict. BEGIN; CREATE SCHEMA f; SET … Read more

How to Replace Multiple Characters in SQL?

One useful trick in SQL is the ability use @var = function(…) to assign a value. If you have multiple records in your record set, your var is assigned multiple times with side-effects: declare @badStrings table (item varchar(50)) INSERT INTO @badStrings(item) SELECT ‘>’ UNION ALL SELECT ‘<‘ UNION ALL SELECT ‘(‘ UNION ALL SELECT ‘)’ … Read more

SQL Query – Concatenating Results into One String [duplicate]

If you’re on SQL Server 2005 or up, you can use this FOR XML PATH & STUFF trick: DECLARE @CodeNameString varchar(100) SELECT @CodeNameString = STUFF( (SELECT ‘,’ + CodeName FROM dbo.AccountCodes ORDER BY Sort FOR XML PATH(”)), 1, 1, ”) The FOR XML PATH(”) basically concatenates your strings together into one, long XML result (something … Read more

MySQL stored procedure vs function, which would I use when?

The most general difference between procedures and functions is that they are invoked differently and for different purposes: A procedure does not return a value. Instead, it is invoked with a CALL statement to perform an operation such as modifying a table or processing retrieved records. A function is invoked within an expression and returns … Read more

How to filter Pandas dataframe using ‘in’ and ‘not in’ like in SQL

You can use pd.Series.isin. For “IN” use: something.isin(somewhere) Or for “NOT IN”: ~something.isin(somewhere) As a worked example: import pandas as pd >>> df country 0 US 1 UK 2 Germany 3 China >>> countries_to_keep [‘UK’, ‘China’] >>> df.country.isin(countries_to_keep) 0 False 1 True 2 False 3 True Name: country, dtype: bool >>> df[df.country.isin(countries_to_keep)] country 1 UK … Read more