Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conversion array types

Tags:

I have in table column, which type is CHARACTER VARYING[] (that is array)

I need concatenate existed rows whith other array

This is my code:

UPDATE my_table SET col = array_cat(col, ARRAY['5','6','7'])    

returned error: function array_cat(character varying[], text[]) does not exist

Reason error is that array types not matches right?

Question: how to convert this array ARRAY['5','6','7'] as CHARACTER VARYING[] type ?

like image 584
Oto Shavadze Avatar asked May 28 '13 07:05

Oto Shavadze


People also ask

How to convert numpy array type?

We have a method called astype(data_type) to change the data type of a numpy array. If we have a numpy array of type float64, then we can change it to int32 by giving the data type to the astype() method of numpy array.

How to convert array type c#?

ConvertAll(TInput[], Converter<TInput, TOutput>) Method is used to convert an array of one type to an array of another type. Syntax: public static TOutput[] ConvertAll<TInput,TOutput> (TInput[] array, Converter<TInput,TOutput> converter); Here, TInput and TOutput is the source array and target array respectively.


1 Answers

Cast to varchar[]:

 > SELECT ARRAY['5','6','7']::varchar[], pg_typeof( ARRAY['5','6','7']::varchar[] );   SELECT ARRAY['5','6','7']::varchar[], pg_typeof( ARRAY['5','6','7']::varchar[] );   array  |      pg_typeof       ---------+---------------------  {5,6,7} | character varying[] 

You can use the PostgreSQL specific ::varchar[] or the standard CAST(colname AS varchar[])... though as arrays are not consistent across database implementations there won't be much advantage to using the standard syntax.

like image 70
Craig Ringer Avatar answered Oct 12 '22 14:10

Craig Ringer