Problem regarding a function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • priyan
    New Member
    • Aug 2007
    • 54

    Problem regarding a function

    Hi all,
    I am having a table, in that a column called code contains a character varying datatype and has subject code in it.....
    subject code will be in the form
    [code=text]
    001
    001.01
    001.02
    02345.01
    002.01
    001.01.01
    001.01.02
    [/code]

    here i want to retrieve only the rows having code with one '.' dot ie., i have to retreive rows having code as 001,002,02345.

    please help me......

    Thanks in advance
    priyan....
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    Originally posted by priyan
    Hi all,
    I am having a table, in that a column called code contains a character varying datatype and has subject code in it.....
    subject code will be in the form
    [code=text]
    001
    001.01
    001.02
    02345.01
    002.01
    001.01.01
    001.01.02
    [/code]

    here i want to retrieve only the rows having code with one '.' dot ie., i have to retreive rows having code as 001,002,02345.

    please help me......

    Thanks in advance
    priyan....
    I am not sure if I get your problem but maybe it is want you want

    select * from tablename where code ~ '^[^.]*\\.[^.]*$';
    See here
    9.7. Pattern Matching # 9.7.1. LIKE 9.7.2. SIMILAR TO Regular Expressions 9.7.3. POSIX Regular Expressions There are three separate approaches to …

    Comment

    • priyan
      New Member
      • Aug 2007
      • 54

      #3
      Originally posted by rski
      I am not sure if I get your problem but maybe it is want you want

      select * from tablename where code ~ '^[^.]*\\.[^.]*$';
      See here
      http://www.postgresql.org/docs/curre...-matching.html


      thank u rski for helping me but i am having another doubt can i retrieve rows from the same table where the code has two dots...ie.,
      [code=text]
      001.01.01
      002.01.02
      [/code]

      Please help me

      Comment

      • priyan
        New Member
        • Aug 2007
        • 54

        #4
        Originally posted by priyan
        thank u rski for helping me but i am having another doubt can i retrieve rows from the same table where the code has two dots...ie.,
        [code=text]
        001.01.01
        002.01.02
        [/code]

        Please help me
        Thank u rski i got the answer thank u verymuch....but if u explain me why we are using such an expression it would be very useful for me and i would be verymuch greatful to u.....
        Thanks
        priyan

        Comment

        • rski
          Recognized Expert Contributor
          • Dec 2006
          • 700

          #5
          Originally posted by priyan
          thank u rski for helping me but i am having another doubt can i retrieve rows from the same table where the code has two dots...ie.,
          [code=text]
          001.01.01
          002.01.02
          [/code]

          Please help me
          Simple

          select * from tablename where code ~ '^[^.]*\\.[^.]*\\.[^.]*$';
          And read what is written on the site
          9.7. Pattern Matching # 9.7.1. LIKE 9.7.2. SIMILAR TO Regular Expressions 9.7.3. POSIX Regular Expressions There are three separate approaches to …

          Comment

          • priyan
            New Member
            • Aug 2007
            • 54

            #6
            Hi rski,
            Thank u very much for helping me
            Priyan

            Comment

            Working...