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 9052861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:17:03+00:00 2026-06-16T13:17:03+00:00

How to delete a particular label from ltree in Postgres table? I have a

  • 0

How to delete a particular label from ltree in Postgres table? I have a table?

Test table:

CREATE TABLE tbl (sno int, path ltree, userid int);

INSERT INTO tbl (sno, path, userid)
VALUES
  (1, '123',             123)
, (2, '123.101',         123)
, (3, '123.101.103',     123)
, (4, '123.101.103.105', 123)
, (5, '123.101.103.107', 123)
, (6, '123.102.104.106', 123)
, (7, '123.102.104.108', 123)
, (8, '123.102.104',     123)
, (9, '123.102',         123);

I want to pass a userid to a query, to remove it from every path in the table. For example, if I pass 101, then 123.101.103 should update as 123.103.

Is it possible to do this directly? Or shall I update path using path replace functions?

I tried the following select query from PHP, but it returns the error below. The same query works properly in phpPgAdmin!?

Query:

$selectPathq=pg_query($con,"select path from myschema.test where path @ '101'")
             or die('could not connect: '. pg_last_error($con));

Error:

could not connect:
ERROR: operator does not exist: myschema.ltree @ unknown at character 63
HINT: No operator matches the given name and argument type(s).
      You might need to add explicit type casts.
  • 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-16T13:17:04+00:00Added an answer on June 16, 2026 at 1:17 pm

    Fix error

    To use the data type ltree and associated functions you need the additional module ltree installed.

    By default, additional modules are installed to the schema public. If your current setting for search_path does not include the schema public, ltree operators are not found. Your error messages hints in this direction:

    ERROR: operator does not exist: myschema.ltree @ unknown at character 63 
    

    To verify, schema-qualify the ltree operator @:

    SELECT path FROM tbl WHERE path operator(public.@) '101';
    

    Does it work now?
    If that’s the root of the problem, you can also set your search_path properly. Check with:

    SHOW search_path;
    

    Set with:

    SET search_path = public; -- add more schemas as needed
    

    The manual about search_path.

    UPDATE path

    If I read your question right and you want to remove a certain item from the path of all rows:

    UPDATE tbl t
    SET    path = nu.path
    FROM  (
       WITH x AS (
          SELECT sno, path, index(path, '101') AS i
          FROM   tbl
          WHERE  path ~ '*.101.*'
          )
       SELECT sno
            , subpath(path, 0, i)
              || CASE WHEN nlevel(path) > i+1 THEN subpath(path, i+1)
                      ELSE '' END AS path
       FROM x
       ) nu
    WHERE nu.sno = t.sno;
    

    (Note that since path is type ltree, the operator ~ in the expression path ~ '*.101.*' is not a regular expression match operator, but a special ltree match operator, and the right term is taken to be of type lquery. It matches any label path containing the label 101.)

    This would leave you with an empty path where you had just 101. You could put this into a trigger AFTER DELETE to purge a certain item from all rows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I delete an item from listbox at particular location and not the
delete from a A where a.ID = 132. The table A contains around 5000
I need to delete rows in a table, such as DELETE FROM TABLE_X WHERE
I am trying to delete particular tables routinely from the sys.tables in vb.net. here
Say we retrieve table data from a php code. 1- Without delete and restore
In my application, I require to delete a particular CONTACT from phone address book,
I have problem removing rows from a table according to the checkbox. Below is
I want to delete a particular row from the listview, in which the data
Hi i all having a requirement to delete particular data from a text file.
I want to delete a string from a particular position in the file. Is

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.