question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Accessing Arrays - placement of index

See original GitHub issue

Documentation feedback


From the documentation it is unclear how to correctly access arrays within objects. The example has the index right after the identifier, but it is not clear if information is an object or array:

select name, information[1]['population'] as population from locations
... where information['population'] is not null
... order by name;

Putting the index first look unintuitive

CREATE TABLE test (a OBJECT);
insert into a values({ id = 1, name = 'foo', tags = ['apple', 'banana', 'pear'], size = 3.1415, valid = true });

SELECT a FROM test limit 100;
-- SELECT OK, 1 row in set (0.005 sec)

SELECT a[1]['tags'] FROM test limit 100;
-- SELECT a[1]['tags'] FROM test limit 100; --> apple

SELECT a['tags'][1] FROM test LIMIT 100;
-- SQLActionException[UnsupportedFeatureException: Nested array access is not supported]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
mfusseneggercommented, Jun 22, 2020

@mechanomi I think this is something where we can also look into changing the behavior or support both versions.

This is indeed rather unintuitive:

cr> SELECT a['tags'] FROM test limit 100;
+-----------------------------+
| a['tags']                   |
+-----------------------------+
| ["apple", "banana", "pear"] |
+-----------------------------+
SELECT 1 row in set (0.007 sec)


cr> SELECT ['apple', 'banana', 'pear'][1] FROM test limit 100;
+---------+
| 'apple' |
+---------+
| apple   |
+---------+
SELECT 1 row in set (0.005 sec)

With an explicit cast it would work:

cr> select a['tags']::text[][1] from test;
+--------------+
| a[1]['tags'] |
+--------------+
| apple        |
+--------------+
1reaction
proddatacommented, Jan 19, 2021

@mechanomi

Looks good to me.

Though I think there is a small typing error Lucine instead of Lucene in the Limitations section … can’t find the pr

Read more comments on GitHub >

github_iconTop Results From Across the Web

Indexing into an Array | Introduction to Computer Science
Arrays are ordered lists. Each element can be accessed by its index (its position in the list). The first element in an array...
Read more >
How to access the elements of an array by index number in C++
We can easily access the elements of a given array by referring to their index number. Remember that in C++, the first element...
Read more >
Array Indexing - Problem Solving with Python
Elements in NumPy arrays can be accessed by indexing. Indexing is an operation that pulls out a select set of values from an...
Read more >
Find the index of an array element in Java - GeeksforGeeks
An element in an array of N integers can be searched using the below-mentioned ... Index position of 5 is: 0 Index position...
Read more >
Array Indexing - MATLAB & Simulink - MathWorks
Every variable in MATLAB® is an array that can hold many numbers. When you want to access selected elements of an array, use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found