Search Postgresql Archives

Format generation_expression

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Currently, I have a problem. I am working on a project with generated columns. I try to implement the generated column feature in the typeorm project. The thing is, I don't want to drop and add a generated column every time the application starts. Therefore I need a way to check whether a generated column _expression_ has changed. 

With select generation_expression from information_schema."columns" c where c.generation_expression is not null; I can retrieve the saved generation _expression_. However, It seems like Postgres optimizes or changes it. Therefore, it is different.  

Example:

I add a column like this:

alter table company add tsv tsvector generated always as (setweight(to_tsvector('german', coalesce(name, '')), 'A') || setweight(jsonb_to_tsvector('german', keywords::jsonb, '["string"]'),'A')) stored;

Now if I try to retrieve the _expression_ with select c.generation_expression from information_schema."columns" c where c.column_name = 'tsv' and c.table_name = 'company'; it is different. 

Input _expression_:
setweight(to_tsvector('german', coalesce(title, '')), 'A') || setweight(to_tsvector('german', coalesce(description, '')), 'B');
What I got from postgres:
(setweight(to_tsvector('german'::regconfig, (COALESCE(name, ''::character varying))::text), 'A'::"char") || setweight(jsonb_to_tsvector('german'::regconfig, keywords, '["string"]'::jsonb), 'A'::"char"))

Postgres formats the query in some way. Is there any way to do this manually? 
Like:
magic_function_to_format_sql(`setweight(to_tsvector('german', coalesce(title, '')), 'A') || setweight(to_tsvector('german', coalesce(description, '')), 'B')`) Returns: (setweight(to_tsvector('german'::regconfig, (COALESCE(name, ''::character varying))::text), 'A'::"char") || setweight(jsonb_to_tsvector('german'::regconfig, keywords, '["string"]'::jsonb), 'A'::"char"))

Then I could check if the saved _expression_ is equal to the formatted one. I tried to find information in the documentation. But I had no luck. 

Best regards,

Nils Bergmann

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux