In PostgreSQL, the AVG()
function computes the average (arithmetic mean) of all the non-null input values, and returns the result.
Author: Ian
How to Find Non-Numeric Values in a Column in MySQL
In MySQL, you can run a query like the following to return non-numeric data from the column.
This can be helpful if you ever find a column that contains numeric data, but it was set up as a varchar
or char
column. You can use this query to find any non-numeric values that might have been inserted into the column. You can then deal with it any way you like, such as convert them to numeric, then change the column type.
PostgreSQL DESCRIBE TABLE Equivalent
Some DBMSs such as Oracle, MySQL, and MariaDB have a DESCRIBE
command that returns information about tables and views. It goes DESCRIBE table
where table is the name of the table or view, and it can also be followed by a column name if you only want information about a specific column.
PostgreSQL doesn’t have a DESCRIBE TABLE
command as such, but there are alternatives.
2 Ways to Return the ASCII Code for a Given Character in MariaDB
MariaDB includes two built-in functions that allow us to get the ASCII code from a given character.
Continue readingDROP TABLE IF EXISTS in SQLite
In SQLite, we can use the IF EXISTS
clause of the DROP TABLE
statement to check whether the table exists or not before dropping it.
Find Non-Numeric Values in a Column in SQL Server
There may be occasions where you need to check a column for non-numeric values. For example, you discover that a column is a varchar
column when it really should be a numeric column.
This is easily done in SQL Server with the ISNUMERIC()
function.
3 Ways to List All Functions in PostgreSQL
Here are three options for listing out all functions in a PostgreSQL database.
Continue readingFormat a Phone Number in SQL Server (T-SQL)
Here are some examples of formatting phone numbers in SQL Server.
This includes examples of formatting numbers in E.164 format (for international numbers), prepending the country code and area code, as well as omitting leading zero from the country code when required.
Continue readingSUM() Function in SQL Server
In SQL Server, the SUM()
aggregate function returns the sum of a given expression.
It can also be used to return the sum of all distinct (unique) values in the expression.
SUM()
only works on numeric columns. Null values are ignored.
Fix Msg 8116 “Argument data type date is invalid for argument 1 of substring function” in SQL Server
If you’re getting SQL Server error Msg 8116 with text that reads Argument data type date is invalid for argument 1 of substring function, it’s because you’re passing the wrong data type to a function – in this case, the SUBSTRING()
function.
You could also see the same error (Msg 8116) in many other contexts – it’s not limited to the SUBSTRING()
function.