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

  • SEARCH
  • Home
  • 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 8737971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:38:24+00:00 2026-06-13T10:38:24+00:00

Postgresql 9.2 DB which automatically collects data from various machines. The DB stores all

  • 0

Postgresql 9.2 DB which automatically collects data from various machines.
The DB stores all the data including the machine id, the firmware, the manufacturer id etc as well as the actual result data. In one stored field (varchar) there are 5 sub fields which are separated by the ^ character.

ACT18!!!8246-EN-2.00013151!1^7.00^F5260046959^H1P1O1R1C1Q1L1^1 (Machine 1)

The order of this data seems to vary from one machine to another. Eg machine 1 2 and 3. The string above shows the firmware version, in this case “7.0” and it appears in sub-field 2. However, another machine sends the data in a different sub-field – in this case sub-field 3 and the value is “1”

BACT/ALERT^A.00^1^^ (Machine 2)

I want to store the values “7.0” and “1” in a different field in a separate table using a CREATE TRIGGER t_machine_id AFTER INSERT function where I can choose which sub-field is used depending on the machine the data has come from.

Is split_part the best function to do this? Can anyone supply an example code that will do this? I can’t find anything in the documentation.

  • 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-13T10:38:26+00:00Added an answer on June 13, 2026 at 10:38 am

    You need to (a) split the data using something like regexp_split_to_table then (b) match which parts are which using some criteria, since you don’t have field position-order to rely on. Right now I don’t see any reliable rule to decide what’s the firmware version and what’s the machine number; you can’t really say where field <> machine_number because if machine 1 had firmware version 1 you’d get no results.

    Given dummy data:

    CREATE TABLE machine_info(data text, machine_no integer);
    INSERT INTO machine_info(data,machine_no) (VALUES
      ('ACT18!!!8246-EN-2.00013151!1^7.00^F5260046959^H1P1O1R1C1Q1L1^1',1),
      ('BACT/ALERT^A.00^1^^',2)
    );
    

    Something like:

    SELECT machine_no, regexp_split_to_table(data,'\^') 
    FROM machine_info;
    

    will give you a table of split data elements with machine number, but then you need to decide which fields are which:

     machine_no |    regexp_split_to_table     
    ------------+------------------------------
              1 | ACT18!!!8246-EN-2.00013151!1
              1 | 7.00
              1 | F5260046959
              1 | H1P1O1R1C1Q1L1
              1 | 1
              2 | BACT/ALERT
              2 | A.00
              2 | 1
              2 | 
              2 | 
    (10 rows)
    

    You may find the output of substituting regexp_split_to_array more useful, depending on whether you can get any useful info from field order and how you intend to process the data.

    regress=# SELECT machine_no, regexp_split_to_array(data,'\^') 
              FROM machine_info;
     machine_no |                      regexp_split_to_array                       
    ------------+------------------------------------------------------------------
              1 | {ACT18!!!8246-EN-2.00013151!1,7.00,F5260046959,H1P1O1R1C1Q1L1,1}
              2 | {BACT/ALERT,A.00,1,"",""}
    (2 rows)
    

    Say there are two firmware versions; version 1 sends code^blah^fwvers^^ and version 2 and higher sends code^fwvers^blah^blah2^machineno. You can then differentiate between the two because you know that version 1 leaves the last two fields blank:

    SELECT
      machine_no,
      CASE WHEN info_arr[4:5] = ARRAY['',''] THEN info_arr[3] ELSE info_arr[2] END AS fw_vers
    FROM (
      SELECT machine_no, regexp_split_to_array(data,'\^')
      FROM machine_info
    ) string_parts(machine_no, info_arr);
    

    results:

     machine_no | fw_vers 
    ------------+---------
              1 | 7.00
              2 | 1
    (2 rows)
    

    Of course, you’ve only provided two sample data, so the real matching rules are likely to be more complex. Consider writing an SQL function to extract the desired field(s) and return them from the array passed.

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

Sidebar

Related Questions

A postgresql 9.1 DB writes data which is sent automatically from a machine. This
I have a database in PostgreSQL which is named DATA in all caps. When
Between Mysql and PostgreSQL,which is suite for very large scale of data..for example, millions
(I am using PostgreSQL) I have a table which stores transactions to an account.
I am working on PostgreSQL and psycopg2. Trying to get feed data which is
I have postgresql (in perlu) function getTravelTime(integer, timestamp), which tries to select data for
i try to create a plpgsql trigger for postgresql 8.3 which automatically partitions a
I have a script in PostgreSQL which restores test database from dump every night.
I have a column in the PostgreSQL database which contains Arabic data. When reading
I am writing a custom report from an Avamar (Postgresql) database which contains backup

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.