Git Product home page Git Product logo

Comments (5)

leafo avatar leafo commented on September 7, 2024

json data should automatically be decoded to a lua table as long as the type of the value is correct coming from postgres. Are you sure it's not accidentally a string when being returned?

from pgmoon.

gzliudan avatar gzliudan commented on September 7, 2024

below is a udf example in my pg database, I want the return value is json or string data type after call udf in lua:
CREATE OR REPLACE FUNCTION get_my_data () RETURNS JSONB
AS
$BODY$
DECLARE
BEGIN
RETURN jsonb_build_object('return_code', 0, 'result', '{"id":"1","name":"test1"}'::JSONB);
END;
$BODY$
LANGUAGE plpgsql;

from pgmoon.

gzliudan avatar gzliudan commented on September 7, 2024

Automatically decoded json to lua table is acceptable. But it's better to provide 2 function and let user choose return type is string or lua table.

from pgmoon.

leafo avatar leafo commented on September 7, 2024

You can cast the value to a string from postgres using ::text

If you want to disable json deserialization on the lua end, you can run:

client:set_type_oid(114, nil)
client:set_type_oid(3802, nil)

from pgmoon.

gzliudan avatar gzliudan commented on September 7, 2024

thank you very much.

from pgmoon.

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.