When using multiple WHEN MATCHED statements, do they all execute, or does only one get executed?

To answer your question, yes, it will only run a single match and then break. However, if you’d like to have logic to allow for conditional matching in the update, the CASE statement is rather useful for this. Something like this as an example: MERGE INTO YourTable USING (VALUES (1, 1, NULL), (0, 0, NULL), … Read more

What are the main differences between OPTION(OPTIMIZE FOR UNKNOWN) and OPTION(RECOMPILE)?

Will OPTION(OPTIMIZE FOR UNKNOWN) reuse cache instead of recompiling each time? Yes, it will. There are two main differences between OPTION(OPTIMIZE FOR UNKNOWN) and OPTION(RECOMPILE) as can be seen from this quote from MSDN: OPTIMIZE FOR UNKNOWN Instructs the query optimizer to use statistical data instead of the initial values for all local variables when … Read more

How to quickly generate SELECT statement with all columns for a table in DataGrip?

In DataGrip, as in other IntelliJ-based IDEs, everything is about source editing. What you want can be achieved this way: Open console Start typing sel, you’ll get completion popup (if not, hit Ctrl+Space) Choose sel here, which is live template for SELECT statement SELECT statement will be generated, asking for table name and column list … Read more

How to convert from varbinary to char/varchar in mysql

Late answer… You can use CAST or CONVERT thus CAST(foo AS CHAR(100)) CONVERT(foo, CHAR(100)) Supported types (5.5) are: BINARY[(N)] CHAR[(N)] DATE DATETIME DECIMAL[(M[,D])] SIGNED [INTEGER] TIME UNSIGNED [INTEGER] You can not cast to varchar directly. There is an open MySQL bug from 2008 which no-one seems to care about and is damn annoying

move data from one table to another, postgresql edition

[Expanding on dvv’s answer] You can move to an existing table as follows. For unmatched schema, you should specify columns. WITH moved_rows AS ( DELETE FROM <original_table> a USING <other_table> b WHERE <condition> RETURNING a.* — or specify columns ) INSERT INTO <existing_table> –specify columns if necessary SELECT [DISTINCT] * FROM moved_rows; But you want … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)