plpythonu AKA am I crazy? or....

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aron Roberts

    #1

    plpythonu AKA am I crazy? or....

    When I create a function with an argument or return type of say an
    integer the data type seems to be passed properly. When trying for
    instance to send or return an integer array it always seems to be passed
    as a string which is very nearly useless. Is there something I am doing
    wrong... or failing that is there just a better way to pass arrays?

    is this a quality of any embedded language or perhaps plpython in
    particular?
    VERSION = 'PostgreSQL 7.4.1 on i386-portbld-freebsd5.1...

    example follows:


    CREATE OR REPLACE FUNCTION zippy(int) RETURNS int AS '
    from types import *
    plpy.notice(typ e(args[0]))
    return args[0]
    ' LANGUAGE plpythonu;

    CREATE OR REPLACE FUNCTION zippy(int[]) RETURNS int[] AS '
    from types import *
    plpy.notice(typ e(args[0]))
    return args[0]
    ' LANGUAGE plpythonu;


    foo=# SELECT zippy(5);
    NOTICE: (<type 'int'>,)
    zippy
    -------
    5
    (1 row)

    foo=# SELECT zippy(CAST('{5, 6,7}' AS int[]));
    NOTICE: (<type 'str'>,)
    zippy
    ---------
    {5,6,7}
    (1 row)



    ---------------------------(end of broadcast)---------------------------
    TIP 9: the planner will ignore your desire to choose an index scan if your
    joining column's datatypes do not match

  • Tom Lane

    #2
    Re: plpythonu AKA am I crazy? or....

    Aron Roberts <aron@slam.cc > writes:[color=blue]
    > When I create a function with an argument or return type of say an
    > integer the data type seems to be passed properly. When trying for
    > instance to send or return an integer array it always seems to be passed
    > as a string which is very nearly useless.
    > is this a quality of any embedded language or perhaps plpython in
    > particular?[/color]

    plpython in particular --- IIRC, its code for mapping between SQL
    datatypes and Python datatypes isn't real bright. If there is a better
    Python construct that arrays could be mapped to, feel free to send in
    a patch ...

    regards, tom lane

    ---------------------------(end of broadcast)---------------------------
    TIP 9: the planner will ignore your desire to choose an index scan if your
    joining column's datatypes do not match

    Comment

    • Joshua D. Drake

      #3
      Re: plpythonu AKA am I crazy? or....

      [color=blue]
      >plpython in particular --- IIRC, its code for mapping between SQL
      >datatypes and Python datatypes isn't real bright. If there is a better
      >Python construct that arrays could be mapped to, feel free to send in
      >a patch ...
      >
      >
      >[/color]
      I am not a python person but could this be the fact that plpython uses the
      pygresql? Instead of psycopg or something?

      Sincerley,

      Joshua D. Drake

      [color=blue]
      > regards, tom lane
      >
      >---------------------------(end of broadcast)---------------------------
      >TIP 9: the planner will ignore your desire to choose an index scan if your
      > joining column's datatypes do not match
      >
      >[/color]


      --
      Command Prompt, Inc., home of Mammoth PostgreSQL - S/ODBC and S/JDBC
      Postgresql support, programming shared hosting and dedicated hosting.
      +1-503-667-4564 - jd@commandpromp t.com - http://www.commandprompt.com
      Mammoth PostgreSQL Replicator. Integrated Replication for PostgreSQL


      ---------------------------(end of broadcast)---------------------------
      TIP 6: Have you searched our list archives?



      Comment

      Working...