In PostgreSQL we can create arrays with the ARRAY
constructor. An array constructor is an expression that builds an array value using values for its member elements.
Category: Object-Relational
How to Check the Current datestyle Setting in PostgreSQL
PostgreSQL has a datestyle
setting that specifies the display format for date and time values, as well as the rules for interpreting ambiguous date input values.
We can check the current value of our datestyle
setting by running SHOW datestyle
.
An Overview of the generate_subscripts() Function in PostgreSQL
PostgreSQL has a generate_subscripts()
function that generates a series comprising the valid subscripts of a given array.
We pass the array to the function, along with the dimension that we want to use. We also have the option of returning the series in reverse order.
Continue readingFix “could not determine polymorphic type because input has type unknown” Error When using array_sample() in PostgreSQL
If you’re getting an error that reads “could not determine polymorphic type because input has type unknown” when using the array_sample()
function in PostgreSQL, it’s probably because your first argument is of the wrong type.
The array_sample()
function requires an array as its first argument. Passing a non-array value will result in an error. The actual error can vary, depending on the argument you pass, but either way, the error is usually due to a non-array being passed.
To fix this error, be sure to pass an array as the first argument when calling the array_sample()
function.
A Quick Overview of the array_shuffle() Function in PostgreSQL
In PostgreSQL array_shuffle()
is a system function that randomly shuffles the first dimension of a given array.
The array_shuffle()
function was introduced in PostgreSQL 16, which was released on September 14th 2023.
Fix “function array_sample(integer, integer) does not exist” in PostgreSQL
If you’re getting an error that reads “function array_sample(integer, integer) does not exist” when using the array_sample()
function in PostgreSQL, it’s probably because your first argument is not an array. In particular, this specific error message implies that the first argument is an integer.
The first argument for this function must be an array.
To fix this error, be sure that your first argument to array_sample()
is an array, not an integer.
An Introduction to the array_sample() Function in PostgreSQL
In PostgreSQL array_sample()
is a system function that returns an array of a specified number of items randomly selected from the given array.
The array_sample()
function was introduced in PostgreSQL 16, which was released on September 14th 2023.
An Overview of the date_subtract() Function in PostgreSQL
PostgreSQL 16 introduced the date_subtract()
function that allows us to subtract an interval from a timestamp with time zone.
It computes times of day and daylight-savings adjustments according to the time zone named by the third argument, or the current TimeZone
setting if that is omitted.
PostgreSQL date_add() Function Explained
PostgreSQL 16 introduced the date_add()
function that allows us to add an interval to a timestamp with time zone.
It computes times of day and daylight-savings adjustments according to the time zone named by the third argument, or the current TimeZone
setting if that is omitted.
2 Ways to Rename the Columns when using VALUES to Create a Constant Table in PostgreSQL
When we use the VALUES
statement to create a constant table, PostgreSQL automatically names the columns column1
, column2
, etc. This saves us from having to provide names for the columns or from getting a blank column header.
But we also have the option of naming the columns ourselves.
Continue reading