Sponsored Content
Full Discussion: missing in script
Operating Systems Linux missing in script Post 302197664 by capri_drm on Wednesday 21st of May 2008 11:03:26 AM
Old 05-21-2008
Thanks ,
let me rephrase it . I want to look for view in a ddl file and then replace it with target schema.VW_<old view name > .

For example,

CREATE VIEW MOUSE_UHC AS SELECT DT_SYS_ID ,DAY_ABBR_CD,LST_DAY_MO_IND,MONTH_NBR,FULL_DT,DAY_NBR FROM DIM_COPY;
CREATE VIEW OPSDM002.TABLE_UHC AS SELECT DAY_ABBR_CD,LST_DAY_MO_IND,MONTH_NBR,FULL_DT,DAY_NBR,LOAD_DT,WEEK_NBR_YR,SEQ_NBR

to

CREATE VIEW OPSDM002.VW_MOUSE_UHC AS SELECT DT_SYS_ID ,DAY_ABBR_CD,LST_DAY_MO_IND,MONTH_NBR,FULL_DT,DAY_NBR FROM DIM_COPY;
CREATE VIEW OPSDM002.VW_TABLE_UHC AS SELECT DAY_ABBR_CD,LST_DAY_MO_IND,MONTH_NBR,FULL_DT,DAY_NBR,LOAD_DT,WEEK_NBR_YR,SEQ_NBR

Problem comes when in some lines view name doesn't have source schema as its prefix .

Here is the code I am using to fix it in vain

#cat view_add.shl
#!/bin/ksh
#####################################################
# use cut and awk to refine the view name
######################################################

if grep "CREATE VIEW" dim_copy.20080516.sql
then
sed -e '/^CREATE VIEW/s/\(.*\.\)\(.*\)/\1VW_\2/' dim_copy.20080516.sql > dim_copy.20080516.sql1
cat dim_copy.20080516.sql1 > dim_copy.20080516.sql
elif grep "CREATE VIEW" dim_copy.20080516.sql | grep -v OPSDM002
then
cat dim_copy.20080516.sql | grep -i "CREATE VIEW" | grep -v OPSDM002 | awk '{print "OPSDM002."$3 }' > dim_copy.20080516.sql1
sed -e '/^CREATE VIEW/s/\(.*\.\)\(.*\)/\1VW_\2/' dim_copy.20080516.sql1 > dim_copy.20080516.sql
else
echo "file does not have view in it "
fi

here is sh -x one

#sh -x view_add.shl
+ [[ -n 1 ]]
+ return
+ grep CREATE VIEW dim_copy.20080516.sql
CREATE VIEW MOUSE_UHC AS SELECT DT_SYS_ID ,DAY_ABBR_CD,LST_DAY_MO_IND,MONTH_NBR,FULL_DT,DAY_NBR FROM DIM_COPY;
CREATE VIEW OPSDM002.TABLE_UHC AS SELECT DAY_ABBR_CD,LST_DAY_MO_IND,MONTH_NBR,FULL_DT,DAY_NBR,LOAD_DT,WEEK_NBR_YR,SEQ_NBR
+ sed -e /^CREATE VIEW/s/\(.*\.\)\(.*\)/\1VW_\2/ dim_copy.20080516.sql
+ 1> dim_copy.20080516.sql1
+ cat dim_copy.20080516.sql1
+ 1> dim_copy.20080516.sql

Thanks a lot for your effort ,

Daya
 

10 More Discussions You Might Find Interesting

1. Red Hat

httpd startup script is missing

I use CenOS Enterprise 5. I've removed existing apache2 then installed the latest apache2. Everything is fine except the original /etc/rc.d/init.d/httpd is now missing. Without this file I can't add httpd to service (commands like "service httpd start" does not work). I have tried to link... (2 Replies)
Discussion started by: aixlover
2 Replies

2. Shell Programming and Scripting

Missing ] error in csh script

The below script gives error: Missing ] #!/bin/csh set MAX=15 set PATTERN='dtsession' set NUM=`ps -eaf | grep -c $PATTERN` echo "No of dtsession = "$NUM if then echo 'Quota exceeded permissible limit' echo 'sending mail...............' mail hiten.r.chauhan@gmail.com<<EOF ... (2 Replies)
Discussion started by: hiten.r.chauhan
2 Replies

3. Shell Programming and Scripting

Bash script - im missing something and cant's figure out what

I just put together a script for work that will essentially automate the migration of our Windows fileserver to my newly created Debian based SAMBA server. My script will create the necessary directories then copy the data over to my new server, after that it will set the ACL's by using... (3 Replies)
Discussion started by: binary-ninja
3 Replies

4. Shell Programming and Scripting

Shell script simple if then :: fi missing ]

If file exists then do stuff else do nothing... #! /bin/sh if then rm /home/dudemgnt/public_html/fileserver/Checks/Daily/RefundChecksDaily.csv cat /home/dudemgnt/public_html/fileserver/Checks/Daily/RefundChecksDaily*.txt|sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' >... (4 Replies)
Discussion started by: Astrocloud
4 Replies

5. Shell Programming and Scripting

Case script to get missing sequence among files

I want to use case statement to find the range of missing sequence in my directory which it has some few ( dat & DAT ) files my directory /home/arm/my_folder/20130428 contains : f01_201304280000.DAT f01_201304280001.DAT f01_201304280003.DAT f02_201304280000.dat f02_201304280002.dat... (2 Replies)
Discussion started by: arm
2 Replies

6. SuSE

How to resolve missing missing dependencies with opensuse 11.3 and 12.3?

Hello, This is a programming question as well as a suse question, so let me know if you think I should post this in programming. I have an application that I compiled under opensuse 12.2 using g77-3.3/g++3.3. The program compiles and runs just fine. I gave the application to a colleague who... (2 Replies)
Discussion started by: LMHmedchem
2 Replies

7. Shell Programming and Scripting

Help with awk script to get missing numbers in column 1

Hello to all, I have show below a file separated by commas. In first column has numbers where the last number is 13. 1,4 2,6 3,7 5,2 6,5 7,5 8,65 9,10 11,78 13,2 What I want to know is which numbers are missing from 1 to 13 (in this case 13 is last number in column 1). My real... (17 Replies)
Discussion started by: Ophiuchus
17 Replies

8. Red Hat

Yum - resolving missing dependencies that are not missing

I am trying to install VirtualBox on RHEL 5 but I need the 32 bit version for 32 bit Windows. When I run yum I get the following: sudo yum localinstall /auto/spvtg-it/spvss-migration/Software/VirtualBox-4.3-4.3.2_90405_el6-1.i686.rpm Loaded plugins: fastestmirror Setting up Local Package... (13 Replies)
Discussion started by: gw1500se
13 Replies

9. Shell Programming and Scripting

Fix script to get missing information

Gents, Can you please help me to fix the following script in order to get complete data as desired. I am missing some data in output. the complete input file is attached. The script I am using is awk '{\ status=substr($0,91,2)\ ind=substr($0,26,1);\ ... (10 Replies)
Discussion started by: jiam912
10 Replies

10. UNIX for Beginners Questions & Answers

Error in ksh script: missing right bracket

I have no idea how to write ksh script, but i'm really in need of help with this. I using fedora 30 and in attempt of runnig attached script i getting those errors, i solved first error by removing excess bracket, but i do not know what should i do with other. Pls sorry for trash post. (8 Replies)
Discussion started by: NullPtr
8 Replies
CREATE 
VIEW(7) PostgreSQL 9.2.7 Documentation CREATE VIEW(7) NAME
CREATE_VIEW - define a new view SYNOPSIS
CREATE [ OR REPLACE ] [ TEMP | TEMPORARY ] VIEW name [ ( column_name [, ...] ) ] [ WITH ( view_option_name [= view_option_value] [, ... ] ) ] AS query DESCRIPTION
CREATE VIEW defines a view of a query. The view is not physically materialized. Instead, the query is run every time the view is referenced in a query. CREATE OR REPLACE VIEW is similar, but if a view of the same name already exists, it is replaced. The new query must generate the same columns that were generated by the existing view query (that is, the same column names in the same order and with the same data types), but it may add additional columns to the end of the list. The calculations giving rise to the output columns may be completely different. If a schema name is given (for example, CREATE VIEW myschema.myview ...) then the view is created in the specified schema. Otherwise it is created in the current schema. Temporary views exist in a special schema, so a schema name cannot be given when creating a temporary view. The name of the view must be distinct from the name of any other view, table, sequence, index or foreign table in the same schema. PARAMETERS
TEMPORARY or TEMP If specified, the view is created as a temporary view. Temporary views are automatically dropped at the end of the current session. Existing permanent relations with the same name are not visible to the current session while the temporary view exists, unless they are referenced with schema-qualified names. If any of the tables referenced by the view are temporary, the view is created as a temporary view (whether TEMPORARY is specified or not). name The name (optionally schema-qualified) of a view to be created. column_name An optional list of names to be used for columns of the view. If not given, the column names are deduced from the query. WITH ( view_option_name [= view_option_value] [, ... ] ) This clause specifies optional parameters for a view; currently, the only supported parameter name is security_barrier, which should be enabled when a view is intended to provide row-level security. See Section 37.4, "Rules and Privileges", in the documentation for full details. query A SELECT(7) or VALUES(7) command which will provide the columns and rows of the view. NOTES
Currently, views are read only: the system will not allow an insert, update, or delete on a view. You can get the effect of an updatable view by creating INSTEAD triggers on the view, which must convert attempted inserts, etc. on the view into appropriate actions on other tables. For more information see CREATE TRIGGER (CREATE_TRIGGER(7)). Another possibility is to create rules (see CREATE RULE (CREATE_RULE(7))), but in practice triggers are easier to understand and use correctly. Use the DROP VIEW (DROP_VIEW(7)) statement to drop views. Be careful that the names and types of the view's columns will be assigned the way you want. For example: CREATE VIEW vista AS SELECT 'Hello World'; is bad form in two ways: the column name defaults to ?column?, and the column data type defaults to unknown. If you want a string literal in a view's result, use something like: CREATE VIEW vista AS SELECT text 'Hello World' AS hello; Access to tables referenced in the view is determined by permissions of the view owner. In some cases, this can be used to provide secure but restricted access to the underlying tables. However, not all views are secure against tampering; see Section 37.4, "Rules and Privileges", in the documentation for details. Functions called in the view are treated the same as if they had been called directly from the query using the view. Therefore the user of a view must have permissions to call all functions used by the view. When CREATE OR REPLACE VIEW is used on an existing view, only the view's defining SELECT rule is changed. Other view properties, including ownership, permissions, and non-SELECT rules, remain unchanged. You must own the view to replace it (this includes being a member of the owning role). EXAMPLES
Create a view consisting of all comedy films: CREATE VIEW comedies AS SELECT * FROM films WHERE kind = 'Comedy'; This will create a view containing the columns that are in the film table at the time of view creation. Though * was used to create the view, columns added later to the table will not be part of the view. COMPATIBILITY
The SQL standard specifies some additional capabilities for the CREATE VIEW statement: CREATE VIEW name [ ( column_name [, ...] ) ] AS query [ WITH [ CASCADED | LOCAL ] CHECK OPTION ] The optional clauses for the full SQL command are: CHECK OPTION This option has to do with updatable views. All INSERT and UPDATE commands on the view will be checked to ensure data satisfy the view-defining condition (that is, the new data would be visible through the view). If they do not, the update will be rejected. LOCAL Check for integrity on this view. CASCADED Check for integrity on this view and on any dependent view. CASCADED is assumed if neither CASCADED nor LOCAL is specified. CREATE OR REPLACE VIEW is a PostgreSQL language extension. So is the concept of a temporary view. SEE ALSO
ALTER VIEW (ALTER_VIEW(7)), DROP VIEW (DROP_VIEW(7)) PostgreSQL 9.2.7 2014-02-17 CREATE VIEW(7)
All times are GMT -4. The time now is 03:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy