If you need a sample database to run some quick tests in SQLite, here are a couple of options.
Continue readingCreate a Database in SQLite
SQLite uses a different syntax for creating databases to what many other relational database management systems use.
Most of the popular relational database management systems such as MySQL, SQL Server, PostgreSQL, and so on, use the CREATE DATABASE
statement to create a database.
When you create a database with SQLite however, you do so by simply providing a filename.
Continue readingCreate a Table in SQLite
To create a table in SQLite, use the CREATE TABLE
statement.
This statement accepts the table name, the column names and their definitions, as well as some other options.
Continue readingCreate a Temporary Table in SQLite
When you create a table in SQLite, you can create it as a permanent table or as a temporary table.
When you create a table in a database that you’ve created, that would be a permanent table. A temporary table is created in the temp
database.
To create a temporary table, you use the same syntax as creating a regular table. The difference is that you use either the TEMP
or TEMPORARY
keyword. You can also (or alternatively) prefix the table name with temp
, which indicates that it will be created in the temporary database.
Attach a Database in SQLite
When using SQLite, you can use the ATTACH DATABASE
statement to add a database file to the current database connection.
When you do this, you attach a database file name and provide a name for the database. If the file exists it will be attached with your chosen name, otherwise it will be created and attached with your chosen name.
Continue readingCheck your SQLite Version
Here are a few ways to check your version of SQLite.
Actually, you probably already saw which version you were using when you connected to SQLite.
In any case, if you found this page, maybe you need another method to check your SQLite version.
Continue readingExtract the Month from a Date in PostgreSQL
In PostgreSQL you can use the EXTRACT()
function to get the month from a date.
You can also use the DATE_PART()
function to do the same thing.
Convert Month Number to Month Name in PostgreSQL
You can use the following code examples in PostgreSQL if you have a month number but you want the month name instead.
Convert Month Name to Month Number in PostgreSQL
In PostgreSQL, if you already have a month name, but you want to convert that name to the month number, you can do this with the EXTRACT()
function.
Get the Month Name from a Date in PostgreSQL
If you’re familiar with PostgreSQL, you might know that you can use the EXTRACT()
and the DATE_PART()
functions to extract the month from a date. But those functions only allow you to extract the month number.
What if you need the month name?
You can get the month name from a date by using the TO_CHAR()
function. This function returns a string based on the timestamp and the template pattern you provide as arguments.