Class 1: Exercise 1 - Hello world

We're going to start off the same way we do with any programming language and work on some basic querying. Querying a database is done via a SELECT statement. Here let's start with hello world:

SELECT 'hello world';

As you can see this is going to return the text because it's a literal string. We can also query tables and certain built in functions as well. As an example Postgres has a built-in function now() which will return what its current time is. See if you can run a query to get it to return the current time as the database views it.

SELECT now();

You can also use built in Postgres functions to change your query output. For example the time query we just issued above, we could add a function called TO_CHAR and tell the system a specific character output format for day, month, year.

SELECT TO_CHAR(NOW(), 'DY, Mon dd, yyyy HH24:MI:SS OF');

Loading terminal...