Skip to main content

Get projection create statement only if table has same name.

  • October 30, 2015
  • 1 reply
  • 10 views

zxcvmnb

Hi, I created a table and it created a projection with same name.

I need create statement for projections only. 

If I do "select export_object('','schm.tab',true)", I get the DDL for table for table and projections. 

 

Is there a way to let vertica know that I want DDL for projection named schm.tab not the table named schm.tab ?

1 reply

Adrian_Oprea_1
Forum|alt.badge.img+1
  • Participating Frequently
  • November 2, 2015

 You can use a semi-dinamic query :).

\t 
-- store sql script here
\o /tmp/exec.sql
-- generate script
with a as (
select 'SELECT EXPORT_OBJECTS('''','''||projection_schema||'.'||projection_name||''',false);' as SQL_SCR,
ROW_NUMBER() over (partition by projection_basename)as prjnum from projections where projection_schema='schema name' and anchor_table_name='table name'
)
select SQL_SCR from a where prjnum = 1 ;
-- store def of proj here
\o /tmp/projection_def.sql
-- execute extrat of proj definition
\i /tmp/exec.sql

  - you can even create a custom User procedure to extract the proj definition based on this logic.

 

hope this helped