Linked Questions
10 questions linked to/from Create an immutable clone of concat_ws
234 votes
9 answers
488k views
How to concatenate columns in a Postgres SELECT?
I have two string columns a and b in a table foo. select a, b from foo returns values a and b. However, concatenation of a and b does not work. I tried : select a || b from foo and select a||', '|...
46 votes
3 answers
183k views
Combine two columns and add into one new column
In PostgreSQL, I want to use an SQL statement to combine two columns and create a new column from them. I'm thinking about using concat(...), but is there a better way? What's the best way to do this?...
37 votes
2 answers
35k views
Why am I getting a an error when creating a generated column in PostgreSQL?
CREATE TABLE my_app.person ( person_id smallserial NOT NULL, first_name character varying(50), last_name character varying(50), full_name character varying(100) generated always as (...
18 votes
2 answers
5k views
Indexing an array for full text search
I am trying to index documents to be searchable on their tag array. CREATE INDEX doc_search_idx ON documents USING gin( to_tsvector('english', array_to_string(tags, ' ')) || ...
0 votes
1 answer
2k views
Slow wildcard search LIKE across multiple columns PostgreSQL/Rails
I'm trying to optimize these slow queries (excuse the SQL mixed with Ruby on Rails): WHERE name ILIKE %<the user's search text>% WHERE lower(NAME) LIKE :search OR lower(BARCODE) LIKE :search OR ...
2 votes
1 answer
2k views
Generated column of tsvector for text array in Postgres (Supabase)
in Postgres (Supabase) I am trying to automatically generate a column from another column which contains a text array of short title variants. The tsvector works just fine and as expected. The other ...
3 votes
3 answers
97 views
PostgreSQL: On insert, combine two values into a 3rd column
I tried to do the following: CREATE TABLE test_table ( column_1 varchar(255), column_2 varchar(255), combined varchar(255) DEFAULT concat(column_1, '_', column_2) ); It produces the ...
3 votes
4 answers
221 views
NULL-input for concatenated string in generated column
I have a table CREATE TABLE IF NOT EXISTS club.climbers ( climber_id SERIAL PRIMARY KEY, climber_first_name VARCHAR(20) NOT NULL, climber_last_name VARCHAR(30) NOT NULL, ...
1 vote
1 answer
261 views
How to make a query with ILIKE filters on multiple columns in two tables?
I have a non-optimized query with ILIKE filters on 6 columns in the first table, and on one more column in the second table. There are more than 13 million records in the table. This request is ...
1 vote
2 answers
55 views
Create an index with concatenation of text fields, taking into account their lengths
I know that I can create an index that uses concatenation as follows: CREATE INDEX idx_table1_field1_field2 ON table1((field1 || field2)); But this is not quite what I need. I will try to explain ...