Re: Strange DOMAIN behavior

Поиск
Список
Период
Сортировка
От Alex Ignatov
Тема Re: Strange DOMAIN behavior
Дата
Msg-id 559E80E0.8000002@postgrespro.ru
обсуждение исходный текст
Ответ на Strange DOMAIN behavior  ("David G. Johnston" <david.g.johnston@gmail.com>)
Ответы Re: Strange DOMAIN behavior  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-sql
Thank you for your reply.
In fact i want to use domains in the following case:

DROP DOMAIN lexema_str CASCADE;
CREATE DOMAIN lexema_str TEXT DEFAULT 'abc' NOT NULL;
DROP TYPE lexema_test CASCADE;
CREATE TYPE lexema_test AS (
   lex  lexema_str,
   lex2 BIGINT
);
DROP TABLE ttt;
CREATE TABLE ttt (
   a lexema_test,
   b BIGINT
);
INSERT INTO ttt (b) VALUES (1);
SELECT *
FROM ttt;
 a | b
---+---
   | 1
(1 row)

 a.lex is null  again not 'abc' as I expected like in plpgsql.

All i want is to have default values in composite types. Feature that Oracle have.
I thought that with domain type it should be possible.





On 09.07.2015 15:49, David G. Johnston wrote:
On Thursday, July 9, 2015, Alex Ignatov <a.ignatov@postgrespro.ru> wrote:
Hello everyone!!!
Got strange DOMAIN behavior in the following plpgsql code:

But i expect that lex = abc!

So default value of DOMAIN type is not set in pgplsql block but:

Is this correct behavior??


If you read the create domain sql command documentation carefully the default clause is only used when inserting into a table that has a column of the domain type that is not explicitly provided a value.  Each language deals with domains differently and the behavior you expect is not currently implemented in pl/pgsql.  If you want a default inside the procedure you need to declare one explicitly.

David J.

-- 
Alex Ignatov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company




Avast logo

This email has been checked for viruses by Avast antivirus software.
www.avast.com


В списке pgsql-sql по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Strange DOMAIN behavior
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Strange DOMAIN behavior