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

Division of integers returns 0

You should cast before you divide, but also you were missing a subquery to get the total count from the table. Here’s the sample. select random_int, count(random_int) as Count, cast(count(random_int) as decimal(7,2)) / cast((select count(random_int) from test) as decimal(7,2)) as Percent from test group by random_int order by random_int;

What are the conditions for encountering a serialization failure in PostgreSQL?

There are many possible causes for serialization failures. Technically, a deadlock between two transactions is one form of serialization failure, and can potentially happen at any isolation level if there are concurrent modifications to the schema (database structure). Since you’re asking about PostgreSQL, you should be aware that in PostgreSQL this type of serialization failure … Read more

Shouldn’t FROM come before SELECT in Sql? [closed]

Yes it is strange and counterintuitive. Hugh Darwen theorises about how this state of affairs came about: Do you take SELECT-FROM-WHERE for granted, or do you, like me, find it rather curious that the System R team should have spurned the normal way of writing expressions of arbitrary complexity in favour of something utterly idiosyncratic … Read more