[SQL] How do I copy part of table from db1 to db2 (and rename the columns)?

2005-08-31 Thread Joost Kraaijeveld
Hi, I want to copy several columns of a source table from db1 to db2, and create the target table and rename the columns in the process. Is that possible in PostgresQL? If so, an example or url for such a command /script would be appreciated... TIA Joost ---(end of

Re: [SQL] How do I copy part of table from db1 to db2 (and rename the columns)?

2005-08-31 Thread Kenneth Gonsalves
On Wednesday 31 Aug 2005 3:30 pm, Joost Kraaijeveld wrote: Hi, I want to copy several columns of a source table from db1 to db2, and create the target table and rename the columns in the process. Is that possible in PostgresQL? If so, an example or url for such a command /script would be

Re: [SQL] [GENERAL] How do I copy part of table from db1 to db2 (and

2005-08-31 Thread Joost Kraaijeveld
On Wed, 2005-08-31 at 12:40 +0200, Roman Neuhauser wrote: check these man pages: pg_dump(1), pg_restore(1), alter_table(7) I am afraid that the problem is more complex. The original database (which is created with SQL_ASCII) contains invalid byte sequences in some columns (target database

Re: [SQL] [GENERAL] How do I copy part of table from db1 to db2 (and

2005-08-31 Thread Thomas Pundt
On Wednesday 31 August 2005 14:00, Joost Kraaijeveld wrote: | So I cannot dump/restore/alter table. I was hoping that piping the text | from stdout to psql that a valid conversion to unicode would take place | but apparently that is not the case. | | Any other ideas? maybe the recode utility can

Re: [SQL] [GENERAL] How do I copy part of table from db1 to db2 (and

2005-08-31 Thread Thomas Pundt
On Wednesday 31 August 2005 14:09, Thomas Pundt wrote: | maybe the recode utility can help then? Something like | | pg_dump -t artik munttest | recode latin1..utf | psql muntfinal sorry to follow up on myself, but that command should read pg_dump -t artik munttest | recode latin1..utf8 |

[SQL] psql commandline

2005-08-31 Thread dIGITx
Hi list the following commandline query doesn`t work. su - postgres -c 'psql --dbname database --command UPDATE users SET pin=12345 WHERE login='admin';' Any idea why? please help... -- GMX DSL = Maximale Leistung zum minimalen Preis! 2000 MB nur 2,99, Flatrate ab 4,99 Euro/Monat:

Re: [SQL] psql commandline

2005-08-31 Thread digit-x
The error is : column admin doesn`t exist What the f... is that db doing? --- Ursprüngliche Nachricht --- Von: Kenneth Gonsalves [EMAIL PROTECTED] An: pgsql-sql@postgresql.org Betreff: Re: [SQL] psql commandline Datum: Wed, 31 Aug 2005 18:13:18 +0530 On Wednesday 31 Aug 2005 6:00 pm,

Re: [SQL] psql commandline

2005-08-31 Thread Kenneth Gonsalves
On Wednesday 31 Aug 2005 6:00 pm, dIGITx wrote: su - postgres -c 'psql --dbname database --command UPDATE users SET pin=12345 WHERE login='admin';' works for me - what is the error you are getting? -- regards kg http://www.livejournal.com/users/lawgon tally ho! http://avsap.org.in ಇಂಡ್ಲಿನಕ್ಸ

Re: [SQL] psql commandline

2005-08-31 Thread Kenneth Gonsalves
On Wednesday 31 Aug 2005 6:24 pm, [EMAIL PROTECTED] wrote: The error is : column admin doesn`t exist try \'admin\' -- regards kg http://www.livejournal.com/users/lawgon tally ho! http://avsap.org.in ಇಂಡ್ಲಿನಕ್ಸ வாழ்க! ---(end of broadcast)---

Re: [SQL] psql commandline

2005-08-31 Thread digit-x
Thx, but already did that. After entering the statement that way my console hangs and only ctrl-d gets it working again. error shown than is: unexpected EOF while looking for matchin '' bash: syntax error: unexpected end of file --- Ursprüngliche Nachricht --- Von: Kenneth Gonsalves [EMAIL

Re: [SQL] psql commandline

2005-08-31 Thread Zac
Be quiet... it is not a db problem: your shell interprets ' characters before sending them to psql so your query becomes UPDATE users SET pin=12345 WHERE login=admin; and column admin (not the literal 'admin') doesn't really exist! Try this: su - postgres -c psql --dbname database --command

Re: [SQL] How do I copy part of table from db1 to db2 (and rename the columns)?

2005-08-31 Thread Greg Sabino Mullane
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 I want to copy several columns of a source table from db1 to db2, and create the target table and rename the columns in the process. Ignoring the db part for now, you can do the first part of your request like this: CREATE TABLE mytable2 AS

Re: [SQL] psql commandline

2005-08-31 Thread Kenneth Gonsalves
On Wednesday 31 Aug 2005 6:43 pm, [EMAIL PROTECTED] wrote: After entering the statement that way my console hangs and only ctrl-d gets it working again. the problem is that the quotes round 'admin' are needed to tell psql that this is a value - but i have no idea how to create the quotes on

Re: [SQL] psql commandline

2005-08-31 Thread Kenneth Gonsalves
On Wednesday 31 Aug 2005 6:49 pm, Zac wrote: su - postgres -c psql --dbname database --command \UPDATE users SET pin=12345 WHERE login='admin';\ works - good thing to know -- regards kg http://www.livejournal.com/users/lawgon tally ho! http://avsap.org.in ಇಂಡ್ಲಿನಕ್ಸ வாழ்க!

[SQL] insert only if conditions are met?

2005-08-31 Thread Henry Ortega
Is there a way to insert a record only if a certain condition is met? Something like: insert into employee values('lastname','firstname',8) where (condition here.. select sum(ofsomething) from xx where sum(ofsomething)0 ) Is this possible at all with just plain SQL?

Re: [SQL] insert only if conditions are met?

2005-08-31 Thread Michael Fuhr
On Wed, Aug 31, 2005 at 11:09:54AM -0400, Henry Ortega wrote: Is there a way to insert a record only if a certain condition is met? Something like: insert into employee values('lastname','firstname',8) where (condition here.. select sum(ofsomething) from xx where sum(ofsomething)0 ) See

Re: [SQL] insert only if conditions are met?

2005-08-31 Thread Henry Ortega
What I am trying to do is * Insert a record for EMPLOYEE A to TABLE A IF the sum of the hours worked by EMPLOYEE A on TABLE A is not equal to N Is this possible? On 8/31/05, Michael Fuhr [EMAIL PROTECTED] wrote: On Wed, Aug 31, 2005 at 11:09:54AM -0400, Henry Ortega wrote: Is there a way

Re: [SQL] [GENERAL] How do I copy part of table from db1 to db2 (and

2005-08-31 Thread Tom Lane
Joost Kraaijeveld [EMAIL PROTECTED] writes: I am afraid that the problem is more complex. The original database (which is created with SQL_ASCII) contains invalid byte sequences in some columns (target database created with UNICODE): There is no magic bullet to make bad data better. If the

Re: [SQL] [GENERAL] How do I copy part of table from db1 to db2

2005-08-31 Thread Joost Kraaijeveld
On Wed, 2005-08-31 at 10:29 -0400, Tom Lane wrote: Joost Kraaijeveld [EMAIL PROTECTED] writes: If, as seems more likely, there's a mishmash of different encodings then you are in for some pain. At the minimum you'll have to separate out Yep. The original database (which is copied to an

Re: [SQL] insert only if conditions are met?

2005-08-31 Thread Ragnar Hafstað
On Wed, 2005-08-31 at 11:49 -0400, Henry Ortega wrote: What I am trying to do is * Insert a record for EMPLOYEE A to TABLE A IF the sum of the hours worked by EMPLOYEE A on TABLE A is not equal to N Is this possible? Sure, given a suitable schema It is not clear to me, if the hours

Re: [SQL] insert only if conditions are met?

2005-08-31 Thread Henry Ortega
Ok. Here's TABLE A emp date hours type JSMITH 08-15-2005 5 WORK JSMITH 08-15-2005 3 WORK JSMITH 08-25-2005 6 WORK I want to insert the ff: 1.) JSMITH 08-15-2005 8 VAC 2.) DOE 08-16-2005 8 VAC #1 should fail because there is already 8 hours entered as being Worked on 08-15-2005 (same date).

Re: [SQL] insert only if conditions are met?

2005-08-31 Thread Ragnar Hafstað
On Wed, 2005-08-31 at 12:49 -0400, Henry Ortega wrote: Ok. Here's TABLE A empdate hours type JSMITH 08-15-2005 5 WORK JSMITH 08-15-2005 3 WORK JSMITH 08-25-2005 6 WORK I want to insert the ff: 1.)

Re: [SQL] insert only if conditions are met?

2005-08-31 Thread Philip Hallstrom
On Wed, 2005-08-31 at 12:49 -0400, Henry Ortega wrote: Ok. Here's TABLE A empdate hours type JSMITH 08-15-2005 5 WORK JSMITH 08-15-2005 3 WORK JSMITH 08-25-2005 6 WORK I want to insert the ff: 1.) JSMITH

Re: [SQL] insert only if conditions are met?

2005-08-31 Thread Scott Marlowe
On Wed, 2005-08-31 at 14:54, Jim C. Nasby wrote: SELECT sum(hours) FROM table WHERE emp_name = 'JSMITH' AND work_date = '8-15-2005'::date will give you the hours. So... INSERT INTO table SELECT blah WHERE (SELECT sum(hours) FROM table WHERE emp_name = 'JSMITH' AND work_date =

Re: [SQL] insert only if conditions are met?

2005-08-31 Thread Daryl Richter
Henry Ortega wrote: Ok. Here's TABLE A empdate hours type JSMITH 08-15-2005 5 WORK JSMITH 08-15-2005 3 WORK JSMITH 08-25-2005 6 WORK I want to insert the ff: 1.) JSMITH08-15-20058VAC 2.) DOE