Giter Site home page Giter Site logo

Comments (4)

marcgreenstock avatar marcgreenstock commented on May 22, 2024 3

Hi @palkan, thanks for looking into this so quickly.

This gem is brilliant btw, thank you so much for your effort.

I see that the docs for hstore_to_jsonb_loose say:

get hstore as a jsonb value, but attempt to distinguish numerical and Boolean values so they are unquoted in the JSON

This is exactly the problem.

It looks as though this should have been fixed in 9.6 commited postgres/postgres@e09996f#diff-0f8b296e470f9ba30622ac12b4cea554 and again amended postgres/postgres@41d2c08#diff-0f8b296e470f9ba30622ac12b4cea554

Make contrib/hstore's hstore_to_jsonb_loose() and hstore_to_json_loose() functions agree on what is a number (Tom Lane)
Previously, hstore_to_jsonb_loose() would convert numeric-looking strings to JSON numbers, rather than strings, even if they did not exactly match the JSON syntax specification for numbers. This was inconsistent with hstore_to_json_loose(), so tighten the test to match the JSON syntax.

And yet the the problem still exists. I'm going to try and look into the bug on hstore_to_jsonb_loose a little more. For now I am working around it by base64 encoding the strings before they are inserted.

from logidze.

bf4 avatar bf4 commented on May 22, 2024 1

I think maybe this should be in the README as a possible error raised by logidze_logger().

We've recently gotten this a few times in

UPDATE \"tender_job_schedule_shifts\" SET \"scheduled_check_in_request_jid\" = '3981465518e9665560300635' WHERE \"tender_job_schedule_shifts\".\"id\" = 581565",

relatedly, while I'm here: I'd also appreciate if there were an error_handling function which I could define to 'rescue' any errors inside logidze without failing the transaction. I do this for a number of my other function.

e.g.

  EXCEPTION
    -- https://www.postgresql.org/docs/11/errcodes-appendix.html
    -- https://www.postgresql.org/docs/11/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING
    WHEN DEADLOCK_DETECTED OR QUERY_CANCELED OR LOCK_NOT_AVAILABLE THEN
      RAISE WARNING 'APP_NOTICE: DATABASE ERROR DETECTED: function % on invoice_ids %. running: %\n', fn_name, invoice_ids, current_query();
      GET STACKED DIAGNOSTICS
          _db_err_sql_state := RETURNED_SQLSTATE,
          _db_err_message := MESSAGE_TEXT,
          _db_err_detail := PG_EXCEPTION_DETAIL,
          _db_err_hint := PG_EXCEPTION_HINT,
          _db_err_context := PG_EXCEPTION_CONTEXT;

      IF COALESCE(current_setting('logidze.meta', true), '') <> '' THEN
        _db_err_responsible_id := current_setting('logidze.meta')::text;
      END IF;

      INSERT INTO database_errors (
        sql_state, message, detail, hint, context,
        fn_name, fn_args, current_query, responsible_id
      ) VALUES (
        _db_err_sql_state, _db_err_message, _db_err_detail, _db_err_hint, _db_err_context,
        fn_name, quote_literal(invoice_ids::text), current_query()::text, _db_err_responsible_id
      );

from logidze.

palkan avatar palkan commented on May 22, 2024

I believe to_jsonb is erroneously attempting to typecast the string, could this be a bug in PG?

to_jsonb works fine http://dbfiddle.uk/?rdbms=postgres_9.6&fiddle=b1f6f9128c3db270785c15f7426583e1 (::jsonb fails but we do not use).

The problem is with hstore_to_jsonb_loose:

# select hstore_to_jsonb_loose('a=>557236406134e62000323100'::hstore);
ERROR:  value overflows numeric format

One way to solve this is to avoid hstore manipulations and calculate the diff using another technique (for example, this one https://github.com/palkan/logidze/blob/master/bench/triggers/keys2_trigger_setup.sql). That would be less performant though (about 1.5x).

from logidze.

palkan avatar palkan commented on May 22, 2024

@bf4 Thanks for the suggestion! Updated the Readme and will create a separate issue regarding exceptions handling.

from logidze.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.