Re: PG meckert *nicht* bei quotes um Zahlen !?

Patryk Kordylewski <[email protected]>
Newsgroups gmane.comp.db.postgresql.german
Message-ID <[email protected]>
Am 07.08.2012 07:47, schrieb Thomas Markus:
> Moins,
>
> Am 06.08.2012 19:24, schrieb Patryk Kordylewski:
>>
>> Verstehe ich jetzt nicht, dein pg_typeof() Beispiel unterstützt doch
>> meine Aussage? :-)
> na nicht ganz. Lässt sich auch verdeutlichen durch die 2 Bsp:
>
> select 1 + '1'
> macht dann int4 + unknown = int4
>
> bzw
> select 1 + '1'::text
> und entsprechend int4 + text
>
> Quotes definieren nicht den Datentyp, aber der ist entscheidend.
> Variante 2 hat glaub ich bis zur 8.3 funktioniert, dann wurde die autom.
> Konvertierung text->xxx abgeschafft in der 8.4
>
> Gruss
> Thomas

Hi,

der + Operator gibt hier doch schon den Kontext und damit die möglichen 
Datentyp vor.

Aber nochmal, ein INSERT INTO (id) VALUES ('1'); hat auch vor der 
Entfernung von expliziten Text-Casts in 8.3 funtkioniert.

8.0:

# CREATE TABLE foo (id INTEGER);
CREATE TABLE
# INSERT INTO foo (id) VALUES ('1');
INSERT 128673153 1
# INSERT INTO foo (id) VALUES ('1'::text);
ERROR:  column "id" is of type integer but expression is of type text
HINT:  You will need to rewrite or cast the expression.


8.2:

# CREATE TABLE foo (id INTEGER);
CREATE TABLE
# INSERT INTO foo (id) VALUES ('1');
INSERT 0 1
# INSERT INTO foo (id) VALUES ('1'::text);
ERROR:  column "id" is of type integer but expression is of type text
LINE 1: INSERT INTO foo (id) VALUES ('1'::text);
                          ^
HINT:  You will need to rewrite or cast the expression.

8.4:

# CREATE TABLE foo (id INTEGER);
CREATE TABLE
# INSERT INTO foo (id) VALUES ('1');
INSERT 0 1
# INSERT INTO foo (id) VALUES ('1'::text);
ERROR:  column "id" is of type integer but expression is of type text
LINE 1: INSERT INTO foo (id) VALUES ('1'::text);
                                      ^
HINT:  You will need to rewrite or cast the expression.

9.1:

# CREATE TABLE foo (id INTEGER);
CREATE TABLE
# INSERT INTO foo (id) VALUES ('1');
INSERT 0 1
# INSERT INTO foo (id) VALUES ('1'::text);
ERROR:  column "id" is of type integer but expression is of type text
LINE 1: INSERT INTO foo (id) VALUES ('1'::text);
                                      ^
HINT:  You will need to rewrite or cast the expression.

Über was diskutiert man hier eigentlich noch? :-)

Gruß

PS: Und hier noch deine 2. Variante auf einer PG 8.0 Büchse - das hat 
auch noch nie funktioniert:

# select 1 + '1'::text;
ERROR:  operator does not exist: integer + text
HINT:  No operator matches the given name and argument type(s). You may 
need to add explicit type casts.

-- 
Sent via pgsql-de-allgemein mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-de-allgemein
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.