There is a table, select * from table :

 ID | name | photos | ------------------------------------------------------------------------------- 1 | name 1 | {http://.../photos_1, http://.../photos_2, http://.../photos_3} 2 | name 2 | {http://.../photos_1, http://.../photos_2, http://.../photos_3} 

I need to display only the first url from the photos column, but not the rest.

To make it so:

 ID | name | photos | ---------------------------------- 1 | name 1 | http://.../photos_1 2 | name 2 | http://.../photos_1 

How to create such a request?

    1 answer 1

    photos look like the default output of an array of strings. That is, if the photos field has a data type of text[] or varchar[] or something similar, then it is necessary:

     select id, name, photos[1] from tablename; 

    The postgresql arrays are numbered from one, so the first element will be under the index 1. If there is no array element or the array itself is NULL, then the result will be NULL.

    • Yes, the photos field has the VARCHAR(220)[] NOT NULL data type. I do your examples, but I get an error. It is невозможно указать тип целого числа, потому что это не массив . Maybe I did not provilno designed? How to implement it correctly? - MegaRoks
    • one
      What exactly is the query turned out? - Small
    • I figured out there was my typo. Thank. - MegaRoks