Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to lowercase postgresql array?

Tags:

postgresql

I need to lowercase array content in PostgreSQL, lower(array['array_content'])) or array[lower('array_content'])) does not work. Actual array is much, much longer.

SELECT * FROM kliendi_aadress WHERE lower(linn) LIKE ANY (array['Tallinn', 'Tartu','Narva'])

Can this even be done?

like image 727
MysteriousNothing Avatar asked Jul 30 '18 08:07

MysteriousNothing


People also ask

How to create array type in PostgreSQL?

To create a column of an array type, the [] symbol is used. The following examples illustrate this: create table contacts ( first_name varchar, last_name varchar, phone_numbers varchar[] ); create table player_scores ( player_number integer, round_scores integer[] );

What is [] in PostgreSQL?

We access array elements using the subscript within square brackets [] . By default, PostgreSQL uses one-based numbering for array elements. It means the first array element starts with number 1.

Does PostgreSQL have arrays?

PostgreSQL allows columns of a table to be defined as variable-length multidimensional arrays. Arrays of any built-in or user-defined base type, enum type, composite type, range type, or domain can be created.

Can you store an array in PostgreSQL?

PostgreSQL database provides a facility to use arrays in the tables to store the same type of data in the bulk form. Arrays are the type of data that are used to store values of the same data type. PostgreSQL allows the column to store data by using multidimensional arrays.

How to convert string column to lowercase in PostgreSQL?

In order to convert the column to lowercase in postgresql we use LOWER () function. LOWER function in postgresql converts string column to lowercase. Let’s see how to We will be using states table.

How to get the lowest element in an array in PostgreSQL?

Given a particular array (e.g. ['foo','bar','baz'] ), array_lower () returns the position of the first (lowest) element, i.e. the lower array bound, which by default is 1: postgres=# SELECT array_lower (ARRAY ['foo', 'bar', 'baz'], 1); array_lower ------------- 1 (1 row)

What is the use of array_lower in PostgreSQL?

ARRAY_LOWER() function. This function is used to return lower bound of the requested array dimension. Syntax: array_lower(anyarray, int) Return Type. int. PostgreSQL Version: 9.3 . Example: PostgreSQL ARRAY_LOWER() function. Code: SELECT array_lower('[0:2]={1,2,3}'::int[], 1); Sample Output: array_lower ----- 0 (1 row)

What is a PostgreSQL array?

PostgreSQL allows columns of a table to be defined as variable-length multidimensional arrays. Arrays of any built-in or user-defined base type, enum type, or composite type can be created.


1 Answers

Well ILIKE solved this problem for me

SELECT * FROM kliendi_aadress WHERE linn ILIKE ANY (array['Tallinn', 'Tartu','Narva']);
like image 94
MysteriousNothing Avatar answered Nov 05 '22 20:11

MysteriousNothing