Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8955185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:29:32+00:00 2026-06-15T14:29:32+00:00

I am currently successfully using a CASE expression to update an empty column based

  • 0

I am currently successfully using a CASE expression to update an empty column based on attributes from other columns. For example

UPDATE table SET cat = CASE 
WHEN term = '{"Boulder"}' then 'Boulder'

However, I need to do the same but on an text array and particularly when an element is in a specific position within that array.

For example if the data looks like

{"Boulder, Tree, Bush"}

WHEN position('Tree' in term) > 0 then 'Boulder'

But I receive an error message

function pg_catalog.position(character varying[], unknown) does not exist

I have used position in a function before so I am not sure why PostgreSQL does not like it in this situation.

Is there a way to using a CASE expression whilst determining the position of a text element within an array.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:29:34+00:00Added an answer on June 15, 2026 at 2:29 pm

    Apparently your term column is defined as an array, e.g. varchar[]. The position function only works with scalar values, not with arrays.

    If you want to test if an element is contained in an array you need to use a different operator: @>

    update foobar
       set cat = 'Boulder'
    where term @> '{"Boulder"}'
    

    The expression '{"Boulder"}' creates an array with a single element. It’s equivalent to array['Boulder'] (which I find more readable). So the above where condition updates all rows where the array term contains all elements of the array on the right hand side of the operator. In this case it’s only a single element you are testing for.

    More details about the array functions and operators can be found in the manual: http://www.postgresql.org/docs/current/static/functions-array.html

    Edit after the requirements have changed

    To find and update only those where boulder is in the first, second or third place, you can use this:

    update foobar
       set cat = 'Boulder'
    where 'Boulder' in (term[1], term[2], term[3]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently using ADFS authentication mechanism to authenticate the user. In that case
currently i create dynamic database using CreateDatabase() method in Entity Framework. it executes sucessfully
I'm currently successfully reading out several properties on our switches over SNMP with php.
I currently have the following objects persisting successfully: Person first name, etc. Exams title,
I successfully got the application icons of the currently installed applications with the following
.NET4 and C#. Created a form, used a DevExpress scheduler successfully. My form currently
I'm currently writing my master thesis and I'm using TortoiseSVN to keep a backup
I am using yui-uploader from YUI 2.6.0 When an upload error occurs, I disable
I've successfully installed this jQuery-based signup form here: http://net.tutsplus.com/tutorials/javascript-ajax/building-a-sleek-ajax-signup-form/ But when I applied it
I have been using json.NET successfully in projects for some time now without any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.