473,396 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Adding new column to existing table

18
hi all,
Question:
i have a table in a database of 6 columns and 630 rows.i want to add one new column to this table and also update this column starting from row 1 to row 630.

System information:
1.Linux ac8d7f39.ipt.aol.com 2.6.9-5.ELsmp #1 SMP Wed Jan 5 19:30:39 EST 2005 i686 i686 i386 GNU/Linux
2. PostgreSQL 7.4.6

My trial:
1. i added one column with ALTER TABLE command
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE only maintable add column id_local text;
it worked well .i checked by select command.
2. then i copied data into that column by COPY FROM command
Expand|Select|Wrap|Line Numbers
  1. COPY maintable (id_local) from 'unix path name of source file' with delimiter as '\n';
the data is copied from file BUT the problem is that it didnt add the data from very 1st row, rather it added data into that column after row 630.
finally row must be 630, BUT it came to be 1260.
please solve or suggest suitable command .
i hope i put my problem explicitly.
with regard
mamoon
May 18 '07 #1
9 10092
michaelb
534 Expert 512MB
Using the COPY command you can only add rows to your existing table, what you need is the UPDATE command.
May 18 '07 #2
mamoon
18
Using the COPY command you can only add rows to your existing table, what you need is the UPDATE command.
thanks michaelb,
actually my problem is different. i wanted to update whole column (630 rows) in one turn which were vaccant earlier. moreover other columns are already filled.
anyway i solved in other way. i manipulated source file and introduced new column with suitable data filled then i run COPY FROM command to already truncated fresh table.it worked.

please tell me about \d command, when i execute \d at database prompt it gives error like this:
Expand|Select|Wrap|Line Numbers
  1. ERROR:  relation "pg_catalog.pg_user" does not exist
  2.  
thanks
mamoon
May 19 '07 #3
michaelb
534 Expert 512MB
... i wanted to update whole column (630 rows) in one turn ...
- you could accomplish this with UPDATE


... when i execute \d at database prompt it gives error like this:
ERROR: relation "pg_catalog.pg_user" does not exist
You may have a corrupted database.
Try to execute these commands and post results
Expand|Select|Wrap|Line Numbers
  1. -- let's see the db version and platform
  2. select version();
  3. -- this may give an error
  4. VACUUM ANALYZE;
  5. -- if no errors reported run the next command
  6. VACUUM FULL;
  7.  
May 19 '07 #4
mamoon
18
- you could accomplish this with UPDATE



You may have a corrupted database.
Try to execute these commands and post results
Expand|Select|Wrap|Line Numbers
  1. -- let's see the db version and platform
  2. select version();
  3. -- this may give an error
  4. VACUUM ANALYZE;
  5. -- if no errors reported run the next command
  6. VACUUM FULL;
  7.  
hi,
results of ur suggested SQL code:
Expand|Select|Wrap|Line Numbers
  1. 1.select version();
version
----------------------------------------------------------------------------------------------------------------------------- PostgreSQL 7.4.6 on i386-redhat-linux-gnu, compiled by GCC i386-redhat-linux-gcc (GCC) 3.4.3 20041125 (Red Hat 3.4.3-6.EL4)
(1 row)
Expand|Select|Wrap|Line Numbers
  1. 2. VACUUM ANALYZE;
VACUUM
Expand|Select|Wrap|Line Numbers
  1. 3. VACUUM FULL;
VACUUM

no error i have seen on the prompt. what next to do.
waiting for reply
with regard
mamoon
May 21 '07 #5
michaelb
534 Expert 512MB
Are you're running with SELinux enabled? If so, this is a known problem.
Due to some issues in early releases of the SELinux policy for Postgres some steps of initdb may fail due to permissions problems.
As a result your database is missing some system views and maybe more (pg_user is a view on the system table pg_shadow), although generally database seems operational, you can create tables and run some basic operations.

Try to upgrade to a more recent version of Postgres (I think the latest release is 8.2)
May 22 '07 #6
mamoon
18
Are you're running with SELinux enabled? If so, this is a known problem.
Due to some issues in early releases of the SELinux policy for Postgres some steps of initdb may fail due to permissions problems.
As a result your database is missing some system views and maybe more (pg_user is a view on the system table pg_shadow), although generally database seems operational, you can create tables and run some basic operations.

Try to upgrade to a more recent version of Postgres (I think the latest release is 8.2)
hi
i am not running SELinux. Instead i am running Red Hat Enterprise Linux.
i think something wrong with initdb. when i run initdb from postgres user prompt
it didnt show that initdb failed.i used the following command
Expand|Select|Wrap|Line Numbers
  1. initdb -D /var/lib/pgsql/data
then following appeared on the terminal
[HTML]The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale en_US.UTF-8.

initdb: directory "/var/lib/pgsql/data" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/var/lib/pgsql/data" or run initdb with an argument other than
"/var/lib/pgsql/data".[/HTML]

i remeber this directly already existed and containing some file before doing initdb. then i run
Expand|Select|Wrap|Line Numbers
  1. postmaster -D /var/lib/pgsql/data
now in data directory a file postmaster.pid appeared containig PID.
i can create table, insert everything and do some jobs. but \d and some commands are not being executed.
if possible suggest where is the problem? either in installing postgres or somewhere else.
coordial thanks
mamoon
May 22 '07 #7
michaelb
534 Expert 512MB
hi
i am not running SELinux. Instead i am running Red Hat Enterprise Linux.
This does not mean that you don't have SELinux enabled.
Check if you have file /etc/selinux/config
If it exists and has the line
SELINUX=enforcing
then you may want to change it to:
SELINUX=disabled
I'm not sure whether this change requires reboot to take effect.

The initdb error you experienced is understandable, you cannot install database in a non-empty directory.
The problem with SELinux policy will not fail initdb, it seems to have worked, but as I noted you'll be missing some system views, like pg_user.
May 22 '07 #8
mamoon
18
This does not mean that you don't have SELinux enabled.
Check if you have file /etc/selinux/config
If it exists and has the line
SELINUX=enforcing
then you may want to change it to:
SELINUX=disabled
I'm not sure whether this change requires reboot to take effect.

The initdb error you experienced is understandable, you cannot install database in a non-empty directory.
The problem with SELinux policy will not fail initdb, it seems to have worked, but as I noted you'll be missing some system views, like pg_user.
ohhh great,
thanks alot to you really thanks.
1.i have emptied data directory and simultaneously set selinux=disabled.
2. after that i applied initdb to empty data directory.
3. well worked
4. then i started postmaster
Expand|Select|Wrap|Line Numbers
  1. postmaster -D /var/lib/pgsql/data
it worked well.postmaster is running in foreground.
now \d is operational.
5. last but not least problem is that when i started postmaster in background with following command:
Expand|Select|Wrap|Line Numbers
  1. postmaster -D /var/lib/pgsql/data > logfile 2>&1 &
it gave error :
Expand|Select|Wrap|Line Numbers
  1. bash-3.00$ bash: logfile: Permission denied
how can i run it in background?
thanks to solve my \d problem.
bye
May 22 '07 #9
michaelb
534 Expert 512MB
... when i started postmaster in background with following command:
Expand|Select|Wrap|Line Numbers
  1. postmaster -D /var/lib/pgsql/data > logfile 2>&1 &
it gave error :
Expand|Select|Wrap|Line Numbers
  1. bash-3.00$ bash: logfile: Permission denied
how can i run it in background?
I guess the logfile already existed and
a) by some reason you don't have a write permission to it (ls -l logfile would show it all)
or
b) some shells do not allow redirecting output to existing file - see noclobber for details.

You can try >> logfile which will append new data to existing file,
but I would recommend using the pg_ctl wrapper script.

See these links for more info
http://www.postgresql.org/docs/8.2/s...ver-start.html
http://www.postgresql.org/docs/8.2/s...pp-pg-ctl.html
May 22 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: dev | last post by:
how create a temp table as a copy of a existing table and then update1 field and insert the hole temp table back in the existing table? please any help? if i have 10 fields in 1 record and...
4
by: Twan Kennis | last post by:
How can I drop a column from an existing table: CREATE TABLE table1 (column1 integer, column2 integer) succeeds. ALTER TABLE table1 DROP COLUMN column2 turns into an error "Error:...
4
by: dave | last post by:
I need to add a column to a table using code. The following works, but only for a new table. How should I change this to alter an existing table? Dim strConn Dim Catalog As New...
3
by: Raj | last post by:
Hi, I am trying to add some more information to the table which already has a lot a data (like 2-3000 records). The new information may be adding 2-3 new columns worth. Now my questions are:...
3
by: GL | last post by:
Hi, Is there a way to add a field to an existing table using a query of some sort (without needing to manually add a field to the table). I know how to do it with a make table query, but I have...
5
by: Wayne Wengert | last post by:
I am using VB ASP.NET. In my page I convert an uploaded XML file to a dataset as follows: Dim ds1 As DataSet = New DataSet ds1.ReadXml(strPathName, XmlReadMode.Auto) Now I want to append...
1
by: aling | last post by:
Damn! SQLServer2000 can't add a NOT NULL COLUMN even in one empty existing table! That is, A is the existing table and it is emtpy, I want to add one NOT NULL COLUMN (col_new) to A using following...
2
by: cyclops | last post by:
Hello everyone, I need to add 10 fields into an existing table which already has 186 fields. but i am not able to do so as i keep getting error message when i try to save the table. Property...
16
by: scoots987 | last post by:
Hi all, I have an existing table(Several actually) that I want to add a column or two or three. I need to have, I think, at least two columns. One for Created date and believe this is a no...
1
by: praween4 | last post by:
friends please let me know how to change the name of the column to an already existing table
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.