Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2009
    Posts
    7

    Unanswered: How convert data in database?

    Hi alll
    i want to convert raw data using math function to voltage value.That function giving as x*625/1024. x =raw data. That converting process happen in PostgreSQL database.But how to do it?TQ all.

  2. #2
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    Create a new table, identical to the original table, except with voltage field.

    Insert data into the new table, using a subselect in the insert statement. Something along the lines of:

    Code:
    Insert into NewTable (Field1, Field2, ... Voltage)
    Select OldTable.Field1, OldTable.Field2, ... OldTable.RawData * 625/1024 as Voltage
    Last edited by loquin; 06-30-09 at 18:41.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  3. #3
    Join Date
    Jun 2009
    Posts
    7
    tq loquin,

    but raw value still not change to voltage value after refreshed.i give the code below.what wrong?

    Code:
     DELETE FROM mts400_results_l
      WHERE mts400_results_l.nodeid = new.nodeid;
     INSERT INTO mts400_results_l(result_time, epoch, nodeid, parent, voltage, humid, humtemp, prtemp, press, taosch0, taosch1, accel_x, accel_y) 
      VALUES (new.result_time, new.epoch, new.nodeid, new.parent, new.voltage, new.humid, new.humtemp, new.prtemp, new.press, new.taosch0, new.taosch1, new.accel_x, new.accel_y);
      SELECT mts400_results_l.voltage* 625/1024 AS voltage
    Code:
    SELECT mts400_results_l.voltage* 625/1024 AS voltage
    that customised code not work?compilling not have any problem but nothing change in data.still same.tq very much for who can helping me...

  4. #4
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    Create a new table with the same fields as the existing table.

    Insert into the NEW table, using a sub-select from the original table as the source for the select.

    You can also use the Create Table As syntax to create a table which contains data from a select...

    Code:
    CREATE TABLE mts400_results_NEW AS
      Select result_time, epoch, nodeid, parent, voltage * 625/1024 as voltage, humid, humtemp, prtemp, press, taosch0, taosch1, accel_x, accel_y
      From mts400_results_1
    From a safety viewpoint, I would not try to update the data 'in place.' Create the new table, copy the old data into the new table, processing the voltage as you do so.

    Then, after you verify that the voltage data is correct, use the new table as a data source for updating the existing table
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  5. #5
    Join Date
    Jun 2009
    Posts
    7
    Code:
    CREATE RULE "cache_mts400_results" AS ON INSERT TO "public"."mts400_results"
    always get error with this code.what wrong?
    Attached Thumbnails Attached Thumbnails error.JPG  
    Last edited by dukati; 07-03-09 at 07:23.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •