0

I made two dimensional array as timestamp type. Then i added an insert like this

'{{2017-03-01 14:00:00},{2017-06-01 21:00:00}}'

How can I get only second element?

Creating of table:

create table client(id SERIAL PRIMARY KEY, full_name VARCHAR(40) NOT NULL, gender VARCHAR(15) NOT NULL, phone_number VARCHAR(20) NOT NULL, card_type VARCHAR(30) NOT NULL, card_period Timestamp[][] NOT NULL );

Then I made some inserts as next:

insert into client (full_name, phone_number, card_type, card_period, gender) values('Mr James Abrams','3805832940003073','Bronze','{{2017-03-01 14:00:00},{2017-06-01 21:00:00}}','man');

When for example I select something

select card_period from client where id = 1;

Its shows like: 2017-03-01T14:00:00,2017-06-01T21:00:00 I tried to select card_period[0:1] - shows only first, if [0:2] then it shows them both

2
  • How you get the first one? Show db schema? How you insert that string? Commented Mar 22, 2017 at 20:19
  • BTW Range types Commented Mar 22, 2017 at 20:48

2 Answers 2

1

The answer already given before me is correct in format, just number of array order are wrong :)

This is how you get 2nd element value:

SELECT card_period[2][1] FROM client WHERE id = 1;
     card_period
---------------------
 2017-06-01 21:00:00
(1 row)
Sign up to request clarification or add additional context in comments.

3 Comments

oh, it's crazy xD. Thank you
That is crazy, what sintaxis you use if want add two rows? like here ?
The syntax is not IMHO crazy if you create 2-dimensional array, then this is common syntax in any programming language to read 1 dimension element and then 2nd dimension element :)
0

SELECT column_name[1][2] FROM the_table

2 Comments

Well then the problem is someplace else, because that is how you access one array. We need more info.
Updated my question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.