[SQL] Position of a field
Hi list, I just would like to know if it is possible to change the position of a field in a table. I am seen in pgAdmin3 that there is a position but on th is application I can't see if there is a place to do that. Regards Ezequias ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster
Re: [SQL] Position of a field
am Tue, dem 27.02.2007, um 8:51:27 -0300 mailte Ezequias Rodrigues da Rocha folgendes: > Hi list, > > I just would like to know if it is possible to change the position of > a field in a table. I am seen in pgAdmin3 that there is a position but > on th is application I can't see if there is a place to do that. Why do you want to do this? You can define the order of the fields in the SELECT-Statement. Other way: you can create a VIEW. And another way: you can recreate the table (create new_table as select from old_table, drop old_table, rename new_tabel to old_table) Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org
Re: [SQL] Position of a field
I understant you inquiry but I don't meant to add all the fields order in an insert statement. IE: insert into table values (value1, value2, value3) is better than insert into table (column1,column2,column3 ...) values (value1, value2, value3) If there is only one way (recreating) that was not good for me. Regards Ezequias 2007/2/27, A. Kretschmer <[EMAIL PROTECTED]>: am Tue, dem 27.02.2007, um 8:51:27 -0300 mailte Ezequias Rodrigues da Rocha folgendes: > Hi list, > > I just would like to know if it is possible to change the position of > a field in a table. I am seen in pgAdmin3 that there is a position but > on th is application I can't see if there is a place to do that. Why do you want to do this? You can define the order of the fields in the SELECT-Statement. Other way: you can create a VIEW. And another way: you can recreate the table (create new_table as select from old_table, drop old_table, rename new_tabel to old_table) Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Atenciosamente (Sincerely) Ezequias Rodrigues da Rocha =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- A pior das democracias ainda é melhor do que a melhor das ditaduras The worst of democracies is still better than the better of dictatorships http://ezequiasrocha.blogspot.com/ ---(end of broadcast)--- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
Re: [SQL] Position of a field
am Tue, dem 27.02.2007, um 9:48:57 -0300 mailte Ezequias Rodrigues da Rocha folgendes: > I understant you inquiry but I don't meant to add all the fields order > in an insert statement. > > IE: > insert into table values (value1, value2, value3) > > is better than > > insert into table (column1,column2,column3 ...) values (value1, > value2, value3) No, it isn't better, because, if you change the table in the future and add new colums, your insert-statement will be failed. If you write your insert with explicit column order, nothing happens, except the new row will be empty. Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net ---(end of broadcast)--- TIP 7: You can help support the PostgreSQL project by donating at http://www.postgresql.org/about/donate
Re: [SQL] Change the Default Database
Hi Rommel, I thought I'd throw a little more input in, as an alternative to psql. I use Ruby on Rails with Postgres, and for testing, it drops the testing database, recreates it and loads the structures dumped from the development database, before running tests - to ensure a clean test every time (it also has a tool for re-building the development database programatically, which one can run before all this). So, Rails has to solve the same problem you have, and it doesn't use psql to do it. My investigation into it's method is as so: 1) Initiate a connection to Pg server via Pg network port. 1.a) Dump dev database structures to file 2) Drop database 'test' 3) Create database 'test' (with correct parameters) 4) Initiate a new connection to Pg server via port, request connection to newly created 'test' database 5) Load dev database structures from file to 'test' database. The key obviously is reconnecting over the port connection and specifying the database you wish to connect to - I think this is how PGAdmin does the job too (when you click on "SQL" you're making a port level connection to the server, specifying which database you want to talk with - from what I can tell, Pg doesn't let you operate across databases, as MS SQL does - one connection = one database). I'm not nearly as expert as others on the list, so any corrections to the above analysis would be welcome. Sincerely, Steve At 04:49 AM 2/27/2007, [EMAIL PROTECTED] wrote: Date: Mon, 26 Feb 2007 18:02:38 -0400 From: "Rommel the iCeMAn" <[EMAIL PROTECTED]> To: Subject: Re: Change Default Database Message-ID: <[EMAIL PROTECTED]> I seem to be blundering a lot today! I thought I was replying to the entire list, didn't realize I replied to one person :-) Nothing was wrong with my script, I assumed that since it was generated by pgAdmin that I could run it inside pgAdmin. It works perfectly when I run it using psql. It is very much like SQL Server's osql command line tool. Thanks to everyone that helped ... So I've learnt three valuable lessons: 1. It's better to execute scripts using the command line tool 'psql'. 2. Make sure I'm replying to the list and not to an individual. 3. Do not post HTML messages!!! :-)) Thanks again everyone. Rommel Edwards Software Developer, Barbados, Caribbean. ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org
Re: [SQL] Syntax Error in COPY when “create function”
hongliu zou escreveu: Am I forgetting some limitation? I get " ERROR: syntax error at or near "$1" SQL state: 42601 "with this CREATE FUNCTION Import1() RETURNS text AS $$ DECLARE path Char(100); BEGIN path = 'C:/zhl/hjs/anc_area.att'; COPY anc_areaAtt FROM path CVS; Try: EXECUTE 'COPY anc_areaAtt FROM ' || path || ' CVS;'; RETURN path; END; $$ LANGUAGE plpgsql; SELECT Import1() ; But COPY can work well when I just put the string in the command: CREATE FUNCTION Import2() RETURNS text AS $$ DECLARE path Char(100); BEGIN COPY anc_areaAtt FROM 'C:/zhl/hjs/anc_area.att' CSV; return path; END; $$ LANGUAGE plpgsql; SELECT Import2() ; |Does this mean the "filename" in COPY command can not be a variable?| Look Executing Dynamic Commands at: http://www.postgresql.org/docs/8.2/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN []s Osvaldo ___ Yahoo! Mail - Sempre a melhor opção para você! Experimente já e veja as novidades. http://br.yahoo.com/mailbeta/tudonovo/ ---(end of broadcast)--- TIP 6: explain analyze is your friend
Re: [SQL] Change the Default Database
Hi Steve, Thanks for the alternative method, I will give that a try as well. It's nice to know there is more than one road to reach a destination. Thanks again, Rommel Edwards Software Developer, Barbados, Caribbean. ---(end of broadcast)--- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
Re: [SQL] Syntax Error in COPY when “create function”
Osvaldo Rosario Kussama <[EMAIL PROTECTED]> writes: >> |Does this mean the "filename" in COPY command can not be a variable?| Got it in one. You can use EXECUTE to put together commands that require a variable in places where PG doesn't allow one. regards, tom lane ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org
[SQL] unsubscribe
unsubscribe Now that's room service! Choose from over 150,000 hotels in 45,000 destinations on Yahoo! Travel to find your fit. http://farechase.yahoo.com/promo-generic-14795097 ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq
