Quantcast

[HACKERS] adding a function to pg_proc.h

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[HACKERS] adding a function to pg_proc.h

Jaime Casanova
I have added a function in sources and added appropiate lines in pg_proc.h

DATA(insert OID = 2560 ( get_view_column_default    PGNSP PGUID 12 f f
t f i 1 2283 "25 25 21" _null_ _null_ _null_ get_view_column_default -
_null_));
DESCR("get default value for view column");

then make; make install; and initdb the data directory.

When i start postgres i look for the function using:

\df get_view*

                               List of functions
   Schema   |          Name           | Result data type | Argument data types  
------------+-------------------------+------------------+----------------------
 pg_catalog | get_view_column_default | anyelement       | text, text, smallint
(1 row)

So far, so good... I will do a test

create table foo (
        col1 serial,
        col2 int2
);
NOTICE:  CREATE TABLE will create implicit sequence "foo_col1_seq" for
serial column "foo.col1"

create view v_foo as select * from foo;
NOTICE:  CREATE VIEW will create implicit INSERT/UPDATE/DELETE rules

alter table v_foo alter col1 set default
get_view_column_default('public'::text, 'foo'::text, 1::smallint);
ERROR:  function get_view_column_default(text, text, smallint) does not exist
HINT:  No function matches the given name and argument types. You may
need to add explicit type casts.


So the question is why ERROR message tell the function doesn't exist,
as you can see the function actually exists.
I change the return data type to bigint and got the same error so it
seems is not a problem of returning anyelement.

any comments will be appreciated.

--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator ;)

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to [hidden email])
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [HACKERS] adding a function to pg_proc.h

Tom Lane-2
Jaime Casanova <[hidden email]> writes:
> I have added a function in sources and added appropiate lines in pg_proc.h
> DATA(insert OID = 2560 ( get_view_column_default    PGNSP PGUID 12 f f
> t f i 1 2283 "25 25 21" _null_ _null_ _null_ get_view_column_default -
> _null_));
> DESCR("get default value for view column");

Try putting the right value for pronargs ;-)

Also, it seems highly unlikely that this function should be marked
as immutable.  Stable sounds more likely.

Also, defining the return type as ANYELEMENT will definitely NOT work,
since none of the input arguments are polymorphic.

                        regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to [hidden email])
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [HACKERS] adding a function to pg_proc.h

Jaime Casanova
On 5/25/05, Tom Lane <[hidden email]> wrote:

> Jaime Casanova <[hidden email]> writes:
> > I have added a function in sources and added appropiate lines in
> pg_proc.h
> > DATA(insert OID = 2560 ( get_view_column_default    PGNSP PGUID 12 f f
> > t f i 1 2283 "25 25 21" _null_ _null_ _null_ get_view_column_default -
> > _null_));
> > DESCR("get default value for view column");
>
> Try putting the right value for pronargs ;-)
>
jeje... fooly of me

> Also, it seems highly unlikely that this function should be marked
> as immutable.  Stable sounds more likely.
>
i don't know when i change this i marked it volatile, but well.. again
it's my fault

> Also, defining the return type as ANYELEMENT will definitely NOT work,
> since none of the input arguments are polymorphic.
>
mmm... This is a problem, there is a way to make a function that can
be used for returning different datatypes depending on the columns

> regards, tom lane
>

--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator ;)

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [HACKERS] adding a function to pg_proc.h

Jaime Casanova
On 5/25/05, Jaime Casanova <[hidden email]> wrote:
> > Also, defining the return type as ANYELEMENT will definitely NOT work,
> > since none of the input arguments are polymorphic.
> >
> mmm... This is a problem, there is a way to make a function that can
> be used for returning different datatypes depending on the columns
>
Ok, i have read in the manual about returning polymorphic types. why
we can't cast the function to the appropiate type to avoid the extra
parameter?

--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator ;)

---------------------------(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

Loading...