Field with default not being set on copy from. 
Author Message
 Field with default not being set on copy from.
Hello all,

It seems that a field declared with a default is not being set when
executing copy from with less field then the table has.

Should I use a rule or a trigger to for setting the default value?

I run 7.3.1

JLL

---------------------------(end of broadcast)---------------------------



Wed, 22 Jun 2005 00:47:59 GMT
 Field with default not being set on copy from.

Quote:

> It seems that a field declared with a default is not being set when
> executing copy from with less field then the table has.

I think you are mistaken.  This works in 7.3:

regression=# create table foo (f1 int, f2 text, f3 int default 42);
CREATE TABLE
regression=# \copy foo(f1,f2) from stdin
1       first
2       second
\.
regression=# select * from foo;
 f1 |   f2   | f3
----+--------+----
  1 | first  | 42
  2 | second | 42
(2 rows)

                        regards, tom lane

---------------------------(end of broadcast)---------------------------



Wed, 22 Jun 2005 05:08:34 GMT
 Field with default not being set on copy from.
Tom,

I am sure you are right.

The last part of my message should have read:

I am running 7.2.3

Time to plan an upgrade...

JLL

Quote:


> > It seems that a field declared with a default is not being set when
> > executing copy from with less field then the table has.

> I think you are mistaken.  This works in 7.3:

> regression=# create table foo (f1 int, f2 text, f3 int default 42);
> CREATE TABLE
> regression=# \copy foo(f1,f2) from stdin
> 1       first
> 2       second
> \.
> regression=# select * from foo;
>  f1 |   f2   | f3
> ----+--------+----
>   1 | first  | 42
>   2 | second | 42
> (2 rows)

>                         regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster


Wed, 22 Jun 2005 06:02:28 GMT
 Field with default not being set on copy from.

Quote:

> The last part of my message should have read:
> I am running 7.2.3

Ah.  In that case, you are right: COPY fills missing fields with nulls,
not default values.  This is fixed in 7.3.

                        regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate

message can get through to the mailing list cleanly



Wed, 22 Jun 2005 06:05:55 GMT
 
 [ 4 post ] 

 Relevant Pages 

1. set default to not null setting?

2. why I am not able to copy db

3. I am not able to Sort ADO Hierarchical record set data

4. UPDATE / Multiple SET not working - fields being set to NULL

5. copying table does not transfer defaults???

6. Copy does not preserve identity or default

7. Setting not Null field to ""(empty string) does not work with CRecordset

8. Unable to set logical field default value to False in Paradox 7

9. Setting Default Property on a new field

10. databound control default value not set

11. Can not set default printer

12. setting null as default to datetime type fields


 
Powered by phpBB® Forum Software