473,382 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

array faults?

Using arrays I came across some strangenesses. Probably this is well
known, but I couldn't find mentions of it.

I am under the impression that this should be an error. Am I wrong?

EXAMPLE 1:
maint=# select ('{{1,2,3},{4,5,6}}'::int[])[1][1:3];
int4
-----------
{{1,2,3}}
(1 row)

Shouldn't this have been just {1,2,3} ?

EXAMPLE 2:
maint=# select ('{{1,2,3},{4,5,6}}'::int[])[2][1:3];
int4
-----------
{{1,2,3},{4,5,6}}
(1 row)

Shouldn't this have been just {4,5,6} (or maybe {{4,5,6}} accepting the
result of example 1) ?
I am trying to do sth like:
maint=# select 1 = any ('{{1,2,3},{4,5,6}}'::int[])[2][1:3];
But that is not working for obvious reasons. This makes arrays pretty
broken for me.

Am I missing anything obvious?

Regards,

David Helgason
Over the Edge Entertainments
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #1
1 1139
David Helgason <da***@uti.is> writes:
EXAMPLE 1:
maint=# select ('{{1,2,3},{4,5,6}}'::int[])[1][1:3];
int4
-----------
{{1,2,3}}
(1 row) Shouldn't this have been just {1,2,3} ?
Nope. It's equivalent to (...)[1:1][1:3]. See section 8.10.3 "Accessing
Arrays" in the current documentation. Note in particular where it says

An array subscripting operation is always taken to represent an array
slice if any of the subscripts are written in the form lower:upper. A
lower bound of 1 is assumed for any subscript where only one value is
specified, ...
Shouldn't this have been just {4,5,6} (or maybe {{4,5,6}} accepting the
result of example 1) ?


See above. You need to write [2:2] not [2].

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

41
by: Berk Birand | last post by:
Hi, I am just learning about the array/pointer duality in C/C++. I couldn't help wondering, is there a way to pass an array by value? It seems like the only way to do is to pass it by...
4
by: stephenma7 | last post by:
Hi, everybody. I am new here. I have encountered these many problems for the last couple of days. I have Linux Fedora Core 3(Gnu G++ 3.4.2), Linux Fedora Core 2 (Gnu G++ 3.3.3), Red Hat 9 (Gnu...
6
by: Sowen | last post by:
hi, I have the following code object obj_1; object obj_2; object obj_3; object *objs = { &obj_1, &obj_2, &obj_3 };
2
by: Dave Kirby | last post by:
I am working on a network management program written in python that has multiple threads (typically 20+) spawning subprocesses which are used to communicate with other systems on the network. This...
1
by: tbatwork828 | last post by:
I've PerfMon-ed our application for several days now and it consistently averages 2000 Page Faults/sec, and accumulates on average about 4 mill page faults during 35 mins. During the same...
4
by: tbatwork828 | last post by:
Related to my other post on Graphics.FillRectangle and a lot of page faults caused by this call... We determine that when Control.DoubleBuffer=true to avoid the flicker effect,...
29
by: yourmycaffiene | last post by:
Okay, this if my first post so go easy on me plus I've only been using C for a couple of weeks. I'm working on a program currently that requires me to read data from a .dat file into a 2d array and...
2
by: David Morgan | last post by:
Hi Have 4Gb of RAM and plenty of free disk. Those page faults are for DLLHOST.EXE using ~370Mb RAM. inetinfo.exe has 403,106,036 page faults at the time of writing and is using ~145Mb RAM. ...
27
by: lovecreatesbea... | last post by:
This code snippet is an exercise on allocating two dimension array dynamically. Though this one is trivial, is it a correct one? Furthermore, when I tried to make these changes to the original...
4
by: none | last post by:
I have an ASP.NET application, hosted on two web servers. I am looking for advice on what should be an acceptable level of page faults on these production servers. If the acceptable level is zero,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.