PostgreSQL Function not returning message in Python 2.7 Script using EXCEPT NOTICEAlgorithm for finding the...

What is the name of this perspective and how is it constructed?

3D buried view in Tikz

Manager has noticed coworker's excessive breaks. Should I warn him?

What is the reason behind this musical reference to Pinocchio in the Close Encounters main theme?

Why does this quiz question say that protons and electrons do not combine to form neutrons?

What does an unprocessed RAW file look like?

Variance of sine and cosine of a random variable

Spells that would be effective against a Modern Day army but would NOT destroy a fantasy one

Why is quixotic not Quixotic (a proper adjective)?

If I have Haste cast on me, does it reduce the casting time for my spells that normally take more than a turn to cast?

Can you wish for more wishes from an Efreeti bound to service via an Efreeti Bottle?

How bad is a Computer Science course that doesn't teach Design Patterns?

Do these large-scale, human power-plant-tending robots from the Matrix movies have a name, in-universe or out?

How can a kingdom keep the secret of a missing monarch from the public?

Why are "square law" devices important?

Can I combine Divination spells with Arcane Eye?

Sets which are both Sum-free and Product-free.

Is layered encryption more secure than long passwords?

What is formjacking?

Can a planet be tidally unlocked?

Can I do anything else with aspersions other than cast them?

Exploding Numbers

Do the speed limit reductions due to pollution also apply to electric cars in France?

Why write a book when there's a movie in my head?



PostgreSQL Function not returning message in Python 2.7 Script using EXCEPT NOTICE


Algorithm for finding the longest prefixWhy cannot I call a table function in iSeries DB2 that I just created?Why would call to scalar function inside a Table Value Function be slower than outside the TVF?Slow fulltext search for terms with high occurenceHow to run ALTER TABLE on a list of tables sequentially in a functionpostgresql function index not being used by queryPostgres function index doesn't work correctly with regular expressionsProper way to index table columns which can be filtered in multiple waysCan't connect to PostgreSQL instance using PythonPostgreSQL Function: Returning Boolean Values depending on whether a table exists













0















I was not able to make the PostgreSQL function return the raised message in the python script it was being called from.



The scenario I wanted to make was:-



1) If the first table was created, a message would be returned saying 'table is created please check' in the python script where these functions would eventually be called, and the second table would not be created.



2) If the first table did not exist the second table would be created. RAISE EXCEPTION stopped the whole function/transaction, and RAISE NOTICE although did the trick with the If STATEMENT in terms of creating the second table if the first existed or not, the 'warning' message did not appear in the python script where it was called.



-- Function: public.insert_equal_geoms(text, text, text, text)

-- DROP FUNCTION public.insert_equal_geoms(text, text, text, text);

CREATE OR REPLACE FUNCTION public.insert_equal_geoms(
param_1 text, -- tindex
param_2 text, --complete topo50
param_3 text, -- error table
param_4 text) -- spatially equal table
RETURNS void AS
$BODY$
DECLARE
v_row_count integer;
BEGIN

v_row_count := NULL;

---make error table if there are any instances of geometries not being equal to topo50 1k layer
EXECUTE format('
DROP TABLE IF EXISTS public.%s;
CREATE TABLE public.%s (
geom geometry(MultiPolygon, 2193),indexname varchar(100),predicate varchar(250));

INSERT INTO public.%s
SELECT a.geom, b.indexname
FROM public.%s as a
LEFT JOIN public.%s as b ON ST_Equals(a.geom, b.geom)
WHERE b.indexname IS NULL;',param_3,param_3,param_3,param_1,param_2);

GET DIAGNOSTICS v_row_count = ROW_COUNT;

IF v_row_count = 0 THEN

EXECUTE format('DROP TABLE IF EXISTS public.%s;
CREATE TABLE public.%s (
geom geometry(MultiPolygon, 2193),indexname varchar(100),predicate varchar(250));

INSERT INTO public.%s
SELECT b.geom, b.tilename, ''Spatially Equal''
FROM public.%s as a, public.%s as b
WHERE ST_Equals(a.geom, b.geom);',param_4, param_4, param_4, param_1, param_2);

RAISE NOTICE '%: Table updated.', timeofday()::timestamp;
ELSE
RAISE NOTICE '%: % errors found. Check error table and resolve issues.', timeofday()::timestamp, v_row_count;
END IF;

END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION public.insert_equal_geoms(text, text, text, text)
OWNER TO postgres;

SELECT public.insert_equal_geoms(public.sample1,public.sample2,public.sample3,public.sample4)


This is how this function was being called in the Python Script;



Python 2.7 SQL function call via psycopg2









share







New contributor




Rose is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    0















    I was not able to make the PostgreSQL function return the raised message in the python script it was being called from.



    The scenario I wanted to make was:-



    1) If the first table was created, a message would be returned saying 'table is created please check' in the python script where these functions would eventually be called, and the second table would not be created.



    2) If the first table did not exist the second table would be created. RAISE EXCEPTION stopped the whole function/transaction, and RAISE NOTICE although did the trick with the If STATEMENT in terms of creating the second table if the first existed or not, the 'warning' message did not appear in the python script where it was called.



    -- Function: public.insert_equal_geoms(text, text, text, text)

    -- DROP FUNCTION public.insert_equal_geoms(text, text, text, text);

    CREATE OR REPLACE FUNCTION public.insert_equal_geoms(
    param_1 text, -- tindex
    param_2 text, --complete topo50
    param_3 text, -- error table
    param_4 text) -- spatially equal table
    RETURNS void AS
    $BODY$
    DECLARE
    v_row_count integer;
    BEGIN

    v_row_count := NULL;

    ---make error table if there are any instances of geometries not being equal to topo50 1k layer
    EXECUTE format('
    DROP TABLE IF EXISTS public.%s;
    CREATE TABLE public.%s (
    geom geometry(MultiPolygon, 2193),indexname varchar(100),predicate varchar(250));

    INSERT INTO public.%s
    SELECT a.geom, b.indexname
    FROM public.%s as a
    LEFT JOIN public.%s as b ON ST_Equals(a.geom, b.geom)
    WHERE b.indexname IS NULL;',param_3,param_3,param_3,param_1,param_2);

    GET DIAGNOSTICS v_row_count = ROW_COUNT;

    IF v_row_count = 0 THEN

    EXECUTE format('DROP TABLE IF EXISTS public.%s;
    CREATE TABLE public.%s (
    geom geometry(MultiPolygon, 2193),indexname varchar(100),predicate varchar(250));

    INSERT INTO public.%s
    SELECT b.geom, b.tilename, ''Spatially Equal''
    FROM public.%s as a, public.%s as b
    WHERE ST_Equals(a.geom, b.geom);',param_4, param_4, param_4, param_1, param_2);

    RAISE NOTICE '%: Table updated.', timeofday()::timestamp;
    ELSE
    RAISE NOTICE '%: % errors found. Check error table and resolve issues.', timeofday()::timestamp, v_row_count;
    END IF;

    END;
    $BODY$
    LANGUAGE plpgsql VOLATILE
    COST 100;
    ALTER FUNCTION public.insert_equal_geoms(text, text, text, text)
    OWNER TO postgres;

    SELECT public.insert_equal_geoms(public.sample1,public.sample2,public.sample3,public.sample4)


    This is how this function was being called in the Python Script;



    Python 2.7 SQL function call via psycopg2









    share







    New contributor




    Rose is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0








      I was not able to make the PostgreSQL function return the raised message in the python script it was being called from.



      The scenario I wanted to make was:-



      1) If the first table was created, a message would be returned saying 'table is created please check' in the python script where these functions would eventually be called, and the second table would not be created.



      2) If the first table did not exist the second table would be created. RAISE EXCEPTION stopped the whole function/transaction, and RAISE NOTICE although did the trick with the If STATEMENT in terms of creating the second table if the first existed or not, the 'warning' message did not appear in the python script where it was called.



      -- Function: public.insert_equal_geoms(text, text, text, text)

      -- DROP FUNCTION public.insert_equal_geoms(text, text, text, text);

      CREATE OR REPLACE FUNCTION public.insert_equal_geoms(
      param_1 text, -- tindex
      param_2 text, --complete topo50
      param_3 text, -- error table
      param_4 text) -- spatially equal table
      RETURNS void AS
      $BODY$
      DECLARE
      v_row_count integer;
      BEGIN

      v_row_count := NULL;

      ---make error table if there are any instances of geometries not being equal to topo50 1k layer
      EXECUTE format('
      DROP TABLE IF EXISTS public.%s;
      CREATE TABLE public.%s (
      geom geometry(MultiPolygon, 2193),indexname varchar(100),predicate varchar(250));

      INSERT INTO public.%s
      SELECT a.geom, b.indexname
      FROM public.%s as a
      LEFT JOIN public.%s as b ON ST_Equals(a.geom, b.geom)
      WHERE b.indexname IS NULL;',param_3,param_3,param_3,param_1,param_2);

      GET DIAGNOSTICS v_row_count = ROW_COUNT;

      IF v_row_count = 0 THEN

      EXECUTE format('DROP TABLE IF EXISTS public.%s;
      CREATE TABLE public.%s (
      geom geometry(MultiPolygon, 2193),indexname varchar(100),predicate varchar(250));

      INSERT INTO public.%s
      SELECT b.geom, b.tilename, ''Spatially Equal''
      FROM public.%s as a, public.%s as b
      WHERE ST_Equals(a.geom, b.geom);',param_4, param_4, param_4, param_1, param_2);

      RAISE NOTICE '%: Table updated.', timeofday()::timestamp;
      ELSE
      RAISE NOTICE '%: % errors found. Check error table and resolve issues.', timeofday()::timestamp, v_row_count;
      END IF;

      END;
      $BODY$
      LANGUAGE plpgsql VOLATILE
      COST 100;
      ALTER FUNCTION public.insert_equal_geoms(text, text, text, text)
      OWNER TO postgres;

      SELECT public.insert_equal_geoms(public.sample1,public.sample2,public.sample3,public.sample4)


      This is how this function was being called in the Python Script;



      Python 2.7 SQL function call via psycopg2









      share







      New contributor




      Rose is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I was not able to make the PostgreSQL function return the raised message in the python script it was being called from.



      The scenario I wanted to make was:-



      1) If the first table was created, a message would be returned saying 'table is created please check' in the python script where these functions would eventually be called, and the second table would not be created.



      2) If the first table did not exist the second table would be created. RAISE EXCEPTION stopped the whole function/transaction, and RAISE NOTICE although did the trick with the If STATEMENT in terms of creating the second table if the first existed or not, the 'warning' message did not appear in the python script where it was called.



      -- Function: public.insert_equal_geoms(text, text, text, text)

      -- DROP FUNCTION public.insert_equal_geoms(text, text, text, text);

      CREATE OR REPLACE FUNCTION public.insert_equal_geoms(
      param_1 text, -- tindex
      param_2 text, --complete topo50
      param_3 text, -- error table
      param_4 text) -- spatially equal table
      RETURNS void AS
      $BODY$
      DECLARE
      v_row_count integer;
      BEGIN

      v_row_count := NULL;

      ---make error table if there are any instances of geometries not being equal to topo50 1k layer
      EXECUTE format('
      DROP TABLE IF EXISTS public.%s;
      CREATE TABLE public.%s (
      geom geometry(MultiPolygon, 2193),indexname varchar(100),predicate varchar(250));

      INSERT INTO public.%s
      SELECT a.geom, b.indexname
      FROM public.%s as a
      LEFT JOIN public.%s as b ON ST_Equals(a.geom, b.geom)
      WHERE b.indexname IS NULL;',param_3,param_3,param_3,param_1,param_2);

      GET DIAGNOSTICS v_row_count = ROW_COUNT;

      IF v_row_count = 0 THEN

      EXECUTE format('DROP TABLE IF EXISTS public.%s;
      CREATE TABLE public.%s (
      geom geometry(MultiPolygon, 2193),indexname varchar(100),predicate varchar(250));

      INSERT INTO public.%s
      SELECT b.geom, b.tilename, ''Spatially Equal''
      FROM public.%s as a, public.%s as b
      WHERE ST_Equals(a.geom, b.geom);',param_4, param_4, param_4, param_1, param_2);

      RAISE NOTICE '%: Table updated.', timeofday()::timestamp;
      ELSE
      RAISE NOTICE '%: % errors found. Check error table and resolve issues.', timeofday()::timestamp, v_row_count;
      END IF;

      END;
      $BODY$
      LANGUAGE plpgsql VOLATILE
      COST 100;
      ALTER FUNCTION public.insert_equal_geoms(text, text, text, text)
      OWNER TO postgres;

      SELECT public.insert_equal_geoms(public.sample1,public.sample2,public.sample3,public.sample4)


      This is how this function was being called in the Python Script;



      Python 2.7 SQL function call via psycopg2







      postgresql functions python except





      share







      New contributor




      Rose is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      Rose is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      Rose is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 6 mins ago









      RoseRose

      11




      11




      New contributor




      Rose is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Rose is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Rose is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "182"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          Rose is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f230473%2fpostgresql-function-not-returning-message-in-python-2-7-script-using-except-noti%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          Rose is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Rose is a new contributor. Be nice, and check out our Code of Conduct.













          Rose is a new contributor. Be nice, and check out our Code of Conduct.












          Rose is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Database Administrators Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f230473%2fpostgresql-function-not-returning-message-in-python-2-7-script-using-except-noti%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Szabolcs (Ungheria) Altri progetti | Menu di navigazione48°10′14.56″N 21°29′33.14″E /...

          Discografia di Klaus Schulze Indice Album in studio | Album dal vivo | Singoli | Antologie | Colonne...

          How to make inet_server_addr() return localhost in spite of ::1/128RETURN NEXT in Postgres FunctionConnect to...