简体   繁体   中英

select array element PostgreSQL

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM