explicit cast error 
Author Message
 explicit cast error

Quote:
> insert into abc
>   (c2, lab, dlab, bdigits) values
>   (5, 'somestring', 'abc123', 3410999762);
> psql returns to me this message:
> psql: ... ERROR: Unable to identify an operator '=' for types 'int4' and 'text'
>       You will have to retype this query using an explicit cast

Try surrounding the bigint integer with single quotes.

                   - Thomas

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



Wed, 22 Dec 2004 03:04:00 GMT
 explicit cast error


Quote:
> Never mind the table def for right now.

That's not a good idea, because I'll bet that inconsistency between abc
and def is exactly your problem.

Quote:
> insert into abc
>   (c2, lab, dlab, bdigits) values
>   (5, 'somestring', 'abc123', 3410999762);
> psql returns to me this message:
> psql: ... ERROR: Unable to identify an operator '=' for types 'int4' and 'text'
>       You will have to retype this query using an explicit cast

I am guessing that (a) you are trying to make a foreign key reference
from an integer column to a text column, and (b) you are not using a
recent Postgres release.  Recent releases would have complained when
you tried to define the foreign-key reference, not on first use.

                        regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command



Wed, 22 Dec 2004 04:19:05 GMT
 explicit cast error

Quote:

> --------------------- the tables ----------------------
> create table abc
> (
>   c1 serial not null primary key,
>   c2 smallint not null,
>   lab text not null,
>   dlab text not null,
>   bdigits bigint null,

>   foreign key (dlab) references def
> );

> create table def
> (
>   defseq serial not null primary key,
>   dlab text unique not null,
>   dset text null,
>   choices text null check (logos in ('','case1','case2', 'case3','case4')),
>   l1 text null,
>   l2 text null,
>   l3 text null,

>   foreign key (dset) references datasets
> );
> -------------------------------------------------------

> One person asked about the release. It's 7.1.3.

Yep, IIRC we didn't start doing at constraint definition
checks for type equivalence until 7.2, so...
The types for a foreign key must be comparable on both sides

In abc, you've got a text field and in def it's refrencing
the primary key which is an int.  That's not allowed.  If
you were running 7.2 it would have errored when you tried
to make the table.  Perhaps you mean for abc(dlab) to
reference def(dlab) in which case the constraint should
read:
 foreign key(dlab) refrences def(dlab)

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command



Wed, 22 Dec 2004 12:16:43 GMT
 
 [ 3 post ] 

 Relevant Pages 

1. Explicit SQL casts?

2. CREATE CAST requires immutable cast function?

3. CREATE CAST requires immutable cast function?

4. check validity of cast before performing cast?

5. SQL Query with FOR XML Explicit results in errors in XML

6. EXPLICIT reports error

7. TOP N in select clause causes error for EXPLICIT mode

8. Error Inserting Explicit Value

9. Error 8626 with FOR XML EXPLICIT, NTEXT column and ORDER BY

10. Error 265: explicit converting of a float dataype to a char datatype

11. Explicit mode gives tag renaming error


 
Powered by phpBB® Forum Software