Tag: sql
Underscores in numeric constants in PostgreSQL 16
SQL and numeric constants NEW in PostgreSQL 16 – support for underscores in integer and numeric constants! I already wrote about support for different notations in the upcoming PostgreSQL 16. This new major version also implements the SQL:202x standard (draft), allowing you to use underscore separators for integers and numeric constants. Using underscore separators in […]
hex, oct, bin integers in PostgreSQL 16
SQL and integer notations NEW in PostgreSQL 16 – support for non-decimal notation of integer constants! PostgreSQL already has powerful support for string constants, with E’\t’, E’\011′, E’\u0009′ and U&’\0009′ all meaning the same thing (a “horizontal tab” character). However, PostgreSQL’s support for numerical constants has – up until now – been rather limited; it […]
Aliases for sub-SELECTS in FROM clause
What are aliases in SQL? SQL aliases in FROM clauses are used to give a result set a temporary name. A result set may be produced by a table or view name, sub-SELECT and/or VALUES clause. An alias is created with the AS keyword, but the grammar allows us to omit it. An alias only […]
Better SQL functions in PostgreSQL v14
We all know and value SQL functions as a handy shortcut. PostgreSQL v14 has introduced a new, better way to write SQL functions. This article will show the advantages of the new syntax. An example of an SQL function Let’s create a simple example of an SQL function with the “classical” syntax so that we […]
Handling Bonus Programs in SQL
Bonus cards, “Miles & more”, bonus points – don’t we all love and hate them at the same time? Recently we had an interesting use case which made me think about sharing some of the techniques we used in this area to reduce client code by writing some clever SQL. This post will show you […]
PostgreSQL 15: Using MERGE in SQL
It’s been many years since the first ideas to implement the MERGE command surfaced on the PostgreSQL mailing list. Now this important feature has finally made it into PostgreSQL core, in PostgreSQL 15. To show people how this vital command works, I have decided to come up with a technical preview to introduce my readers […]
PostgreSQL: mapping timestamps (date_bin)
date_bin and timestamps in PostgreSQL Date and time are relevant to pretty much every PostgreSQL application. A new function was added to PostgreSQL 14 to solve a problem which has caused challenges for many users out there over the years: How can we map timestamps to time bins? The function is called date_bin. What people […]
Primary Keys vs. UNIQUE Constraints in PostgreSQL
Most of my readers will know about primary keys and all kinds of table constraints. However, only a few of you may have ever thought about the difference between a primary key and a UNIQUE constraint. Isn’t it all just the same? In both cases, PostgreSQL will create an index that avoids duplicate entries. So […]
SHOW TABLES in PostgreSQL: what’s wrong with it?
In this article, I will answer the questions: why isn’t there a SHOW TABLES command in PostgreSQL, when will SHOW TABLES in PostgreSQL be available, and how do I list tables with native PostgreSQL methods? Why isn’t there a SHOW TABLES command in PostgreSQL? People who come from MySQL are always asking the same question: […]
PostgreSQL: LIMIT vs FETCH FIRST ROWS … WITH TIES
Most people in the SQL and in the PostgreSQL community have used the LIMIT clause provided by many database engines. However, what many do not know is that LIMIT / OFFSET are off standard and are thus not portable. The proper way to handle LIMIT is basically to use SELECT … FETCH FIRST ROWS. However, […]
Understanding LATERAL joins in PostgreSQL
LATERAL joins are one of the lesser-known features of PostgreSQL and other relational databases such as Oracle, DB2 and MS SQL. However, LATERAL joins are a really useful feature, and it makes sense to take a look at what you can accomplish with them. Inspecting FROM more closely Before we dive into LATERAL, it makes […]
About cross join in PostgreSQL
© Laurenz Albe 2021 For many people, “cross join” is something to be afraid of. They remember the time when they forgot the join condition and the DBA was angry, because the query hogged the CPU and filled the disk. However, there are valid use cases for cross joins which I want to explore in […]