E
E
Eugene Wolf2016-11-27 20:57:34
PostgreSQL
Eugene Wolf, 2016-11-27 20:57:34

How to cast an array of numbers from a VARCHAR field to INTEGER type in PostgreSQL?

Good day dear!
There is this request:

SELECT field1::integer FROM table1 WHERE field1 ~ E'^\\d+$' AND field1::integer > 3;

Which allows us to select fields of type VARCHAR and cast them to type INTEGER for subsequent comparison of these with numeric values.
Now there is a need to perform such an operation with the VARCHAR[] array field. That is, we have a VARCHAR[] array field that contains a certain set of values. You need to select each of the array values, try to convert it to the INITEGER type, if it is not given (for example, because the field contains characters other than numbers) - just ignore this value, with the values ​​\u200b\u200bthat are given - carry out resp. comparison operation, like:
... WHERE 10 < ANY(array_column).
----------
Colleagues, thank you very much for your help! JsQuery is generally a great thing, it's a pity the LIKE operator is not supported :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2016-11-27
@Wolfnsex

So you don't need to code shit - do normalization or use json field
||
Betray an array in server YaP
||
Write a procedure

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question