Re: Using incorrect default-value type

From: David Johnston <polobo(at)yahoo(dot)com>
To: Arturo Pie Joa <arturotd08(at)yahoo(dot)ca>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Using incorrect default-value type
Date: 2012-10-14 20:07:50
Message-ID: EF983917-672F-41B6-8130-22B56F98A205@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Oct 14, 2012, at 15:49, Arturo Pie Joa <arturotd08(at)yahoo(dot)ca> wrote:

> Hello,
>
> I have found a strange behavior in postgreSQL when adding columns with defaults of a domain type in a schema different from public. This is the example to reproduce it:
>
> CREATE SCHEMA schema_1;
> CREATE DOMAIN schema_1.text AS text;
>
> SET search_path TO schema_1, pg_catalog;
>
> CREATE TABLE test
> (
> col1 text DEFAULT 'some value'
> );
>
> SELECT a.attname,
> pg_get_expr(d.adbin, d.adrelid) AS default
> FROM pg_attribute a LEFT JOIN pg_attrdef d
> ON a.attrelid = d.adrelid AND a.attnum = d.adnum
> WHERE a.attrelid = 'schema_1."test"'::regclass
> AND a.attnum > 0
> ORDER BY a.attnum;
>
> Last query will return:
> col1 | "'some value'::pg_catalog.text"
>
> I don't understand why it is using "pg_catalog.text", when it should be using "schema_1.text", or in this case the query should return just "text" since the search path is using "schema_1".
>
> Furthermore, if I open pgAdmin and select "col1" in "test" table, SQL pane will show:
> ALTER TABLE schema_1.test ALTER COLUMN col1 SET DEFAULT 'some value'::text;
>
> but I believe, it should show:
> ALTER TABLE schema_1.test ALTER COLUMN col1 SET DEFAULT 'some value'::schema_1.text;
>
> Is this a bug or am I missing something?
>
> Thanks,
>
> Arturo
>

What you are doing (name overloading) seems inadvisable regardless of whether it should work are described. My guess is that the system searches for an actual type first and only if it fails to find a matching type then looks for a matching domain.

David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2012-10-14 20:35:07 Re: Using incorrect default-value type
Previous Message Arturo Pie Joa 2012-10-14 19:49:58 Using incorrect default-value type