1

I have a column in my database called: "CIElabOne" which is of the type numeric [] ("CIElabOne" numeric[]) and thus contains values like: {9.766934377517181,0.0011685082518947398,-0.0023119569625251746}

I cant access the values independently, when executing the following SQL query:

SELECT "fileName" FROM "clothItems" WHERE "CIElabOne[1]" = '9.766934377517181'

The result is : ERROR: column "CIElabOne[1]" does not exist

Selecting CIElabOne as a whole is not a problem but I need to evaluate each of the elements of the array. I don't know why this happens I am following the guide http://www.postgresql.org/docs/9.1/static/arrays.html but I don't seem to find the error

This is my real sql query in java:

sqlTwo = "SELECT \"fileName\" FROM \"clothItems\" WHERE \"CIElabOne[1]\" = '"
                    + inputColorOneCIELAB[0]
                    + "' AND \"CIElabOne[2]\" = '"
                    + inputColorOneCIELAB[1]
                    + "' AND \"CIElabOne[3]\" = '"
                    + inputColorOneCIELAB[2]
                    + "' and \"gender\" = '"
                    + inputGender
                    + "' AND \"shape\" <> '"
                    + inputShape
                    + "'";

inputColorOneCIELAB[] is an array of doubles

4
  • Could you please show your real Java code? It's unclear what your query really is with all these useless quotes. Commented Oct 31, 2015 at 10:58
  • Why do you quote every column name and value? Just use select filename from clothitems where cielabone[1] = ? and .... Use a prepared statement and pass parameters instead of using concatenation. Commented Oct 31, 2015 at 11:42
  • I dont think quoting is a problem, I have 5 other sql queries with the cuoting and work perfectly Commented Oct 31, 2015 at 11:53
  • 2
    So, it was a quoting problem after all... Commented Oct 31, 2015 at 12:22

1 Answer 1

3

The array subscript operator must be outside the quoted identifier name, otherwise it's treated as part of the identifier.

"CIElabOne[1]"

means "the column named CIElabOne[1]." You want:

"CIElabOne"[1]

which means "the first array element of the column CIElabOne.

Sign up to request clarification or add additional context in comments.

1 Comment

@user3540466 Another good reason why quoted identifiers should be avoided

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.