473,757 Members | 8,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding new column to existing table

18 New Member
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.ao l.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 10114
michaelb
534 Recognized Expert Contributor
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 New Member
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 Recognized Expert Contributor
... 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 New Member
- 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 Recognized Expert Contributor
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 New Member
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 Recognized Expert Contributor
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=enforci ng
then you may want to change it to:
SELINUX=disable d
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 New Member
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=enforci ng
then you may want to change it to:
SELINUX=disable d
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=disable d.
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 Recognized Expert Contributor
... 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
6581
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 about 100 records and a field.status=1 in a existing_table and i want to create a temp_table with all the recordse and values of the existing_table and then update the field.status to 2 and insert in 1 query the temp_table in the existing_table
4
7083
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: Operation cancelled."
4
2275
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 ADOX.Catalog Dim Table As ADOX.Table
3
4908
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: (1)Is it a good idea to add new columns to the existing table? then it will create these new columns for all old records, will it not result in wasting a lot of space?? (2)Is it a good idea to create a new table with the new information and have as a...
3
53772
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 a specific need to only add a new field to a table if possible. Here's a simplified example of what I'm trying to do: I get a file with the following two fields: First Name
5
2957
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 all the rows of ds1 to an existing table in an SQL Server database. I know I can do things like looping through the dataset and issuing Update SQL statements to do this but I suspect there is a better
1
3486
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 T-SQL statement, then it will fail. ALTER TABLE A ADD col_new varchar(600) NOT NULL GO
2
1274
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 value is too large. (Error 3309) help on this says "This error can appear if: You have exceeded the maximum number of columns allowed in a table or the maximum number of locks for a single file. The indexed property of a field was changed from...
16
4918
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 brainer in that I just add the column and set the default to getdate(). Two, for tracking a modified date of the row of data. I want to keep it simple. What do I do to track the modify date of a row in SQL Server 2005? Anytime any data changes on a...
1
13496
by: praween4 | last post by:
friends please let me know how to change the name of the column to an already existing table
0
9489
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9298
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10072
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7286
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6562
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.