HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Adding value to int array

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
arrayintvalueadding

Problem

I looked at the postgres website and to add a integer to a intarray it says int[] + int. I have a int array in a table and I eventually want to insert the array with another value added to it into another table. So testing with a select statement I am not sure where I am messing up.

So a am doing:

SELECT myarray + 9::integer from foo
ERROR: operator does not exist: smallint[] + integer


What am I missing. It looks just like the postgres website on intarrays from 9.1 postgres.

Solution

Use the concatenation operator

myarray || 9


Details in the manual: https://www.postgresql.org/docs/current/9.1/functions-array.html

Code Snippets

myarray || 9

Context

StackExchange Database Administrators Q#173615, answer score: 4

Revisions (0)

No revisions yet.