Thread: BUG #4402: Column expansion: date comes wthout a cast

BUG #4402: Column expansion: date comes wthout a cast

From
"Joachim Unger"
Date:
The following bug has been logged online:

Bug reference:      4402
Logged by:          Joachim Unger
Email address:      jo.unger@arcor.de
PostgreSQL version: 8.3
Operating system:   Windwos XP Professional 32 Bit
Description:        Column expansion: date comes wthout a cast
Details:

The column expansion lists date types without a date cast.

Here is an example where I'm using NEW inside a trigger:
[...]
ins_sql := 'INSERT INTO ' ||   quote_ident(new_child_table) || '('
||col_names(new_child_table) || ') VALUES ' || NEW;
RAISE NOTICE 'INSERT: %',ins_sql;
EXECUTE ins_sql;
[...]

Execution of the generated  SQL throws an error:

ERROR:  column "adate" is of type date but expression is of type integer
LINE 1: INSERT INTO table_2008_1(id,adate) VALUES (1,2008-01-30)
HINT:  You will need to rewrite or cast the expression.

That hint describes exactly what is missing:(1,DATE '2008-01-30')

Re: BUG #4402: Column expansion: date comes wthout a cast

From
Euler Taveira de Oliveira
Date:
Joachim Unger escreveu:
> The column expansion lists date types without a date cast.
>
And all of the text types too.

> Here is an example where I'm using NEW inside a trigger:
> [...]
> ins_sql := 'INSERT INTO ' ||   quote_ident(new_child_table) || '('
> ||col_names(new_child_table) || ') VALUES ' || NEW;
> RAISE NOTICE 'INSERT: %',ins_sql;
> EXECUTE ins_sql;
> [...]
>
Why aren't you expanding it yourself? Currently, PostgreSQL doesn't have
a function that does the quoting-if-needed automagically.


--
  Euler Taveira de Oliveira
  http://www.timbira.com/