Обсуждение: adding a function to pg_proc.h
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 ;)
Jaime Casanova <systemguards@gmail.com> 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
On 5/25/05, Tom Lane <tgl@sss.pgh.pa.us> wrote: > Jaime Casanova <systemguards@gmail.com> 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 ;)
On 5/25/05, Jaime Casanova <systemguards@gmail.com> 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 ;)