Re: [GENERAL] Strategy for Primary Key Generation When Populating Table

2012-02-09 Thread Rich Shepard
On Thu, 9 Feb 2012, Merlin Moncure wrote: If you can't (which happens on various type of data), then the surrogate is giving the illusion of row uniqueness when there isn't one. Ah, but each row is unique. However, there is no consisten set of non NULL values that can consistently define a

[GENERAL] Single Table Select With Aggregate Function

2012-01-03 Thread Rich Shepard
I'm probably not seeing the obvious so I keep making the same mistake. The table holds water chemistry data from multiple streams, sites within each stream, sampling dates, and many chemical constituents. What I need to do are three things: 1.) Find the date and site for the maximum value

Re: [GENERAL] Single Table Select With Aggregate Function

2012-01-03 Thread Rich Shepard
On Tue, 3 Jan 2012, Tom Lane wrote: You can do that type of thing using subqueries, eg select ... from mytab where col = (select max(col) from mytab where ...) Thanks, Tom. That's what I thought I needed. or if you don't mind a nonstandard construct, consider SELECT

Re: [GENERAL] Single Table Select With Aggregate Function

2012-01-03 Thread Rich Shepard
On Wed, 4 Jan 2012, Ondrej Ivanič wrote: window functions might be helpful: http://www.postgresql.org/docs/9.1/static/tutorial-window.html Thanks. I'll carefully read this. Much appreciated, Rich -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to

[GENERAL] Recommended Protocol: Adding Rows to Table

2011-11-25 Thread Rich Shepard
The data originated in a spreadsheet and, based on my experience, contains duplicate records. After reformatting there are 143,260 rows to insert in the table. The approach I tried seems to have problems (explained below) and I would like to learn the proper way to insert rows in either an

Re: [GENERAL] Recommended Protocol: Adding Rows to Table

2011-11-25 Thread Rich Shepard
On Fri, 25 Nov 2011, David Johnston wrote: Simplistically you load all the data into a staging table that has no natural primary key and then write a query that will result in only a single record for whatever you define as a primary key. Insert the results of that query into the final table.

Re: [GENERAL] Recommended Protocol: Adding Rows to Table

2011-11-25 Thread Rich Shepard
On Fri, 25 Nov 2011, Scott Mead wrote: Why don't you first load the data into a table (no primary key), then use SQL to find your dups? once loaded: SELECT primary_key_column, count(1) from table group by 1 having count(1) 1; At least then, you'll really know what you're in for. You can

[GENERAL] Blank Numeric Column For INSERT

2011-11-23 Thread Rich Shepard
I am trying to load 143K rows into a postgres-9.0.5 table from an ASCII text file. The file consists of INSERT INTO ... statements and the VALUES are comma delimited. One column is numeric (REAL), but ~10K rows have that value missing, and postgres rejects the lines. The column does not have

Re: [GENERAL] Blank Numeric Column For INSERT

2011-11-23 Thread Rich Shepard
On Wed, 23 Nov 2011, Richard Broersma wrote: My pg.dump files show nulls as: \N Richard, Mine do, too. But, that's not what postgres wants to see in the .sql file. It takes it as a newline (\n) whether quoted or not. Thanks, Rich -- Sent via pgsql-general mailing list

Re: [GENERAL] Blank Numeric Column For INSERT

2011-11-23 Thread Rich Shepard
On Wed, 23 Nov 2011, Tom Lane wrote: In an insert command, you need to either write NULL or omit the column from the column list; empty expressions aren't syntactically correct. (Note that the latter option actually results in inserting the column's default, not necessarily null...) Tom, I

[GENERAL] Syntax To Create Table As One In Another Database

2011-11-15 Thread Rich Shepard
I need a pointer to the appropriate docs that show me how to specify a table in a different database. What I want is to CREATE TABLE tablename AS TABLE otherdatabasesame_tablename; but using a period (dot) to separate the source database and table name doesn't work. My searches of the 9.0.x

Re: [GENERAL] Syntax To Create Table As One In Another Database

2011-11-15 Thread Rich Shepard
On Tue, 15 Nov 2011, David Johnston wrote: Aside from roles/users each database exists in isolation and so what you describe cannot be done. The syntax you describe something.tablename is reserved for SCHEMA usage within PostgreSQL. David, This was pointed out to me. What I did was

Re: [GENERAL] I need to load mysql dump to postgres...

2011-10-13 Thread Rich Shepard
On Thu, 13 Oct 2011, unclebob wrote: Looks like it's not exactly what I need. It migrates data from db to db, but I need to get data from a file(mysql dump) and load it to postgres. It's a large file and I don't want to load it to mysql first and then migrate data. thanks. When you write,

[GENERAL] psql died in midst of session

2011-10-12 Thread Rich Shepard
This has not happened before to me. I'm running postgres-9.0.4 on Slackware-13.1. I've been working on the command line using the psql shell updating and fixing a table when the application failed on me: PANIC: could not open file pg_xlog/00010046 (log file 0, segment 70):

Re: [GENERAL] psql died in midst of session [FIXED]

2011-10-12 Thread Rich Shepard
On Wed, 12 Oct 2011, Rich Shepard wrote: Please advise me how to recover from whatever happened so I can get postgres up and running again. Fixed. I noticed that the referenced pg_log/ file was owned by root.root rather than by postgres.users so I chown and that did the trick. Strange

[GENERAL] SELECT statement not working as intended

2011-10-10 Thread Rich Shepard
I'm trying to query the table to extract the single highest value of a chemical by location and date. This statement gives me all the values per stream, site, and date: SELECT str_name, site_id, sample_date, max(quant) FROM chemistry WHERE hydro = 'Humboldt' group by str_name, sample_date,

Re: [GENERAL] SELECT statement not working as intended

2011-10-10 Thread Rich Shepard
On Mon, 10 Oct 2011, Merlin Moncure wrote: remove the sample_date the group by and the select list. by having it in there you are asking for the max for each specific sample date. merlin, That tells me the max quant but not on what date. Do I write a nested SELECT to get that, too?

Re: [GENERAL] SELECT statement not working as intended

2011-10-10 Thread Rich Shepard
On Mon, 10 Oct 2011, Henry Drexler wrote: you are also grouping by sample date, those are the largest values for the criteria you have set out in the group by. Henry, As I asked Merlin, what is necessary to get the date that maximum quantity was recorded? A nested SELECT? Thanks, Rich

Re: [GENERAL] SELECT statement not working as intended

2011-10-10 Thread Rich Shepard
On Mon, 10 Oct 2011, John R Pierce wrote: the complication is, there can be more than one date with the same maximum value, so such a query would be ambiguous, or it would return multiple rows. John, The likelihood of that is diminishingly small. Thanks, Rich -- Sent via pgsql-general

Re: [GENERAL] Selecting All Columns Associated With Maximum Value of One Column

2011-10-06 Thread Rich Shepard
On Wed, 5 Oct 2011, Chris Curvey wrote: Based on your subject line, I'm guessing that you want something like this: select quant, param, site_id, sample_date, str_name from chemistry where param = 'TDS' and str_name = 'BurrowCrk' and quant = (select max(quant) from chemistry where param =

Re: [GENERAL] Selecting All Columns Associated With Maximum Value of One Column

2011-10-06 Thread Rich Shepard
On Wed, 5 Oct 2011, David Johnston wrote: Max is an aggregate function and thus requires one of: 1) GROUP BY 2) Window - max(quant) OVER (PARTITION BY ...) To be present in the query. David, I was unaware of the windows functions. I see the document page for 9.0.5 so I'll carefully read

Re: [GENERAL] Selecting All Columns Associated With Maximum Value of One Column

2011-10-06 Thread Rich Shepard
On Wed, 5 Oct 2011, David Johnston wrote: 2) Window - max(quant) OVER (PARTITION BY ...) Hmm-m-m. I have a problem here emulating the example on the document page. Regardless of which column is first after SELECT postgres tells me that column does not exist. select site_id, sample_date,

Re: [GENERAL] Selecting All Columns Associated With Maximum Value of One Column

2011-10-06 Thread Rich Shepard
On Thu, 6 Oct 2011, David Johnston wrote: Missing the FROM before chemistry D'oh! Obviously not yet sufficiently cafinated this morning. Also, with the window function can I limit the output to a single str_name and param? Not directly. After you create the windowed result you can

[GENERAL] Selecting All Columns Associated With Maximum Value of One Column

2011-10-05 Thread Rich Shepard
A table (chemistry) has columns named site_id, sample_date, param, quant, and str_name (among other columns). I want to find the site_id, sample_date, and quant for a specific str_name and param. I cannot get the proper syntax in the SELECT statement. My attempts are variations of, SELECT

Re: [GENERAL] Quick-and-Dirty Data Entry with LibreOffice3?

2011-09-30 Thread Rich Shepard
On Fri, 30 Sep 2011, Vincent Veyron wrote: You get a lot more : this gives you an interface to Postgresql inside an Emacs buffer. Thank you. Rich -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription:

Re: [GENERAL] Quick-and-Dirty Data Entry with LibreOffice3?

2011-09-28 Thread Rich Shepard
On Wed, 28 Sep 2011, Vincent Veyron wrote: I'm not sure what 'INSTALL INTO ... statements' are, but are you aware of the very convenient 'M-x sql-postgres' in emacs? Vincent, I have a SQL major mode for emacs. Don't know that it's specific to postgres but it is automatically invoked when I

Re: [GENERAL] Quick-and-Dirty Data Entry with LibreOffice3?

2011-09-27 Thread Rich Shepard
On Mon, 26 Sep 2011, planas wrote: Which version of LO are you using and which Linux? I have some experience with using LO as a front-end when pgAdmin is not the best tool. LO-3.4.3 on Slackware-13.1/32-bit. I have noticed that with Ubuntu you need to use the 3.3.x series from the

Re: [GENERAL] Quick-and-Dirty Data Entry with LibreOffice3?

2011-09-27 Thread Rich Shepard
On Tue, 27 Sep 2011, Richard Broersma wrote: I'd recommend using JDBC ODBC driver for PostgreSQL. Open Office via direct JDBC has a hard time with some PostgreSQL data-types. ODBC handles this by converting these to a text representation that Open Office can handle. Richard, LibreOffice

Re: [GENERAL] Quick-and-Dirty Data Entry with LibreOffice3?

2011-09-27 Thread Rich Shepard
On Tue, 27 Sep 2011, Richard Broersma wrote: ODBC handles this by converting these to a text representation that Open Office can handle. Richard, Progress has been made. I built and installed unixODBC from slackbuilds.org and now the hangup is identifying the location and name of the

Re: [GENERAL] Quick-and-Dirty Data Entry with LibreOffice3?

2011-09-27 Thread Rich Shepard
On Tue, 27 Sep 2011, John R Pierce wrote: Eeek! you NEVER directly access the postgres data files. rather, you connect to postgres via a socket, and ask it to fetch the data for you, thats just how it works. Well, when the LO odbc window asks for the location of the database to which to

[GENERAL] Quick-and-Dirty Data Entry with LibreOffice3?

2011-09-26 Thread Rich Shepard
Rather than writing an application right now to enter data into a table I thought of trying LibreOffice as a front end. But, it doesn't seem to work as OO.o did. This leads to two questions: 1) Can someone show me how to use LO as a front end to a postgres table? 2) Is there another

[GENERAL] /usr/local/pgsql/data permissions

2011-09-23 Thread Rich Shepard
My server just crashed because a CPU-intensive build threatened to overheat the processor so the system shut down. When I rebooted and tried to start postgres the attempt failed because `data directory /usr/local/pgsql/data has group or world access'. As far as I can recall, it's always been

Re: [GENERAL] /usr/local/pgsql/data permissions

2011-09-23 Thread Rich Shepard
On Fri, 23 Sep 2011, John R Pierce wrote: Indeed, 700 are the correct privs. John, When it started and worked I assumed that was the case. But, I've not before had directory permissions change when a system crashed. Cue the Twilight Zone theme. Thanks, Rich -- Sent via pgsql-general

Re: [GENERAL] /usr/local/pgsql/data permissions

2011-09-23 Thread Rich Shepard
On Fri, 23 Sep 2011, John R Pierce wrote: did the system run some sort of fsck autorepair when it restarted? thats about the only thing I could think of that might have messed with the permissions. The file system is ext3 so it did restore from the journals. Anyway, now I know if I

Re: [GENERAL] Apparent Problem With NULL in Restoring pg_dump

2011-09-17 Thread Rich Shepard
On Fri, 16 Sep 2011, Andy Colson wrote: Sorry, I should have been a little more clear, but, at least you got things cleaned up. PG has a huge number of data manipulation functions. If you have to export data out of a database in order to massage it, then that's a failure of a database. PG

Re: [GENERAL] Apparent Problem With NULL in Restoring pg_dump

2011-09-16 Thread Rich Shepard
On Thu, 15 Sep 2011, Andy Colson wrote: First you need to trim the \n and spaces: andy=# insert into junk values (E'GW-22'); INSERT 0 1 andy=# insert into junk values (E'GW-22 \n'); INSERT 0 1 andy=# insert into junk values (E'GW-22 \n'); Andy, Here's what worked for me: nevada=#

Re: [GENERAL] Apparent Problem With NULL in Restoring pg_dump

2011-09-16 Thread Rich Shepard
On Thu, 15 Sep 2011, Andy Colson wrote: Trim it up: andy=# select '['|| rtrim(trim(trailing E'\n' from a)) || ']' from junk; Andy, Scrolling through the table with rows ordered by date and chemical I find no duplicates ... so far. However, what I do find is that the above did not work:

Re: [GENERAL] Apparent Problem With NULL in Restoring pg_dump [SOLVED]

2011-09-16 Thread Rich Shepard
On Fri, 16 Sep 2011, Rich Shepard wrote: Scrolling through the table with rows ordered by date and chemical I find no duplicates ... so far. However, what I do find is that the above did not work: Turns out there was 1 duplicate. Reading the psql man page and making an error in the \copy

Re: [GENERAL] Cryptic Error Message Importing Table Dump

2011-09-15 Thread Rich Shepard
On Thu, 15 Sep 2011, Alban Hertroys wrote: The text in the error is a tab character, so maybe you have an extra tab somewhere? Alban, The column separators are tabs. I've checked a few rows above and below the cited one and find only a single tab between columns. If not, perhaps the

Re: [GENERAL] Cryptic Error Message Importing Table Dump [RESOLVED]

2011-09-15 Thread Rich Shepard
On Thu, 15 Sep 2011, Adrian Klaver wrote: In your editing of the file did you happen to edit out the \. that is at the end of the COPY data? Adrian, Ah, shoot! I did ... based on an earlier message. That was the problem. Many thanks, once again, Rich -- Sent via pgsql-general mailing

[GENERAL] Apparent Problem With NULL in Restoring pg_dump

2011-09-15 Thread Rich Shepard
The .sql file produced by pg_dump is properly terminated with '\.' as the last line, yet I continue to encounter this error: ERROR: invalid input syntax for type real: CONTEXT: COPY chemistry, line 47363, column quant: when trying to re-create the table. It appears that this

Re: [GENERAL] Apparent Problem With NULL in Restoring pg_dump [UPDATE]

2011-09-15 Thread Rich Shepard
On Thu, 15 Sep 2011, Rich Shepard wrote: It appears that this error is generated when a row has a missing value in the 'quant' column and the column contains '\N' in the text file. For example, \N GW-22 2005-03-09 Depth to Water \N Feet\N \N \N \N

Re: [GENERAL] Apparent Problem With NULL in Restoring pg_dump

2011-09-15 Thread Rich Shepard
On Thu, 15 Sep 2011, Andy Colson wrote: Can you pg_dump again, but use --inserts? Maybe it'll offer some hints. Andy, Only if I restore /usr/local/pgsql/data/* from the backup tape of a few days ago. I need to drop the table before trying to insert it. Also, do you have the right line

Re: [GENERAL] Apparent Problem With NULL in Restoring pg_dump

2011-09-15 Thread Rich Shepard
On Thu, 15 Sep 2011, Andy Colson wrote: To restore, you are using: psql dbname filename correct? Andy, Same error. BTW, what prompted this was my discovery that about 1400 rows with site_id = GW-22 had a newline appended to that string. Using emac's search-and-replace I took those off

Re: [GENERAL] Apparent Problem With NULL in Restoring pg_dump

2011-09-15 Thread Rich Shepard
On Thu, 15 Sep 2011, Andy Colson wrote: Ah, I see there was a prior thread about this problem. You said you'd missed the \. and said it was resolved. So is this a same file or a different one? Andy, Same file, unfortunately. Rich -- Sent via pgsql-general mailing list

Re: [GENERAL] Apparent Problem With NULL in Restoring pg_dump

2011-09-15 Thread Rich Shepard
On Thu, 15 Sep 2011, Alban Hertroys wrote: You appear to have two tabs after Depth to Water, which would be one too many. Alban, I thought that I had caught all the double tabs. Thanks for seeing this one. Now I'm back to the tabs-in-real-columns issue: ERROR: invalid input syntax

Re: [GENERAL] Apparent Problem With NULL in Restoring pg_dump

2011-09-15 Thread Rich Shepard
On Thu, 15 Sep 2011, Andy Colson wrote: It's simpler to use sql to do this. Can you restore the table? Andy, OK. I need to provide a new client with filled in paperwork so I can get paid. I'll return to this as soon as that's done. Yes, I'll restore from the backup drive (yea,

[GENERAL] Identifying Reason for Column Name Returned by SELECT

2011-09-14 Thread Rich Shepard
I run this SELECT statement on a table: select distinct(site_id) from chemistry order by site_id; and in the returned set I see: GW-21 GW-22 GW-22 + GW-24 I want to find that row returning 'GW-22 +' because I believe it should be 'GW-23'. However, my attempts to retrieve

Re: [GENERAL] Identifying Reason for Column Name Returned by SELECT

2011-09-14 Thread Rich Shepard
On Wed, 14 Sep 2011, Steve Crawford wrote: I suspect you have a multi-line entry and the '+' is just indicating that the field continues. Steve, et al.: It's not multi-line, but malformed. Try ...where site_id ~ 'GW-22'... (this may take a while if the table is very large). This

Re: [GENERAL] Identifying Reason for Column Name Returned by SELECT

2011-09-14 Thread Rich Shepard
On Wed, 14 Sep 2011, Richard Broersma wrote: I'm confused. Richard, Apparently, I am also confused. Doing too many things simultaneoulsy. Do you want to UPDATE the affected records to GW-22. Or do you want to ALTER the table to add a column constraint to prevent malformed site_id's in

Re: [GENERAL] Identifying Reason for Column Name Returned by SELECT

2011-09-14 Thread Rich Shepard
On Wed, 14 Sep 2011, Merlin Moncure wrote: It *is* mult-line. psql uses a '+ to show line breaks: Merlin, Yep. I discovered this when I dumped the table as an ASCII text file and saw the '\n' after the site_id string on some rows. I've no idea how it got there. Thanks, Rich -- Sent via

[GENERAL] Cryptic Error Message Importing Table Dump

2011-09-14 Thread Rich Shepard
Now that I fixed the rows that had the inadvertent newlines in one column, I'm trying to read in the fixed table from the .sql file produced by pg_dump. I know there are duplicate rows now that I removed the newlines, and those are easily fixed (although the reported line numbers don't match

Re: [GENERAL] Looking for an intro-to-SQL book which is PostgreSQL-friendly

2011-09-02 Thread Rich Shepard
On Fri, 2 Sep 2011, Josh Berkus wrote: I'm looking for an intro-to-SQL book for teaching a class, one aimed at folks who know *nothing* about RDBMSes, which is not based on MySQL or MSAccess. The ones I have on my desk are all based on one or the other, except The Manga Guide to Databases,

[GENERAL] COPY failure on directory I own

2011-08-30 Thread Rich Shepard
I need to understand why this command fails: nevada=# copy statdata to '/home/rshepard/projects/nevada/queenstake/stats/chem.csv' with delimiter '|' null as 'NA' CSV HEADER; ERROR: could not open file /home/rshepard/projects/nevada/queenstake/stats/chem.csv for writing: Permission denied

Re: [GENERAL] COPY failure on directory I own

2011-08-30 Thread Rich Shepard
On Tue, 30 Aug 2011, Scott Ribe wrote: Where is the server and where are you? You are issuing a command to the server to create a file at that path on the server. It's sitting right here next to my desk. That host is the network server and my workstation. Yes, my home directory (and all

Re: [GENERAL] COPY failure on directory I own

2011-08-30 Thread Rich Shepard
On Tue, 30 Aug 2011, Scott Mead wrote: In this case, it's not about YOU and your permissions, it's about the server. The COPY command writes data as the 'postgres' operating system user (or whichever user owns the postgres backend process). Scott, Ah so. User 'postgres' is in the same

Re: [GENERAL] COPY failure on directory I own [FIXED]

2011-08-30 Thread Rich Shepard
On Tue, 30 Aug 2011, Rich Shepard wrote: Ah so. User 'postgres' is in the same group ('users') as I am, so I need to change the perms on the data directory to 775 to give postgres write access. That did the trick. Thanks for the lesson, Scott. Rich -- Sent via pgsql-general mailing list

Re: [GENERAL] COPY failure on directory I own

2011-08-30 Thread Rich Shepard
On Wed, 31 Aug 2011, Craig Ringer wrote: Yeah, or use the client/server copy protocol via psql's \copy command. Craig, I was aware there was a back-slash version but did not recall when its use is appropriate nor just how to use it. Thanks, Rich -- Sent via pgsql-general mailing list

[GENERAL] Not Seeing Syntax Error

2011-08-17 Thread Rich Shepard
For several INSERT INTO rows I get a syntax error when the quant column is NULL for one specific parameter. I don't see my error. Here is an example row: psql:insert.sql:8: ERROR: syntax error at or near , LINE 1: ...ALUES ('9609-0759','BC-1.5','1996-09-19','Arsenic',,'mg/L');

Re: [GENERAL] Not Seeing Syntax Error

2011-08-17 Thread Rich Shepard
On Wed, 17 Aug 2011, Thom Brown wrote: The error message points to the problem. No value, not even NULL, has been specified for 5th column. Either put DEFAULT or NULL in there. You can't put nothing. I was under the impression (obviously wrong) that a blank field was accepted as a NULL.

Re: [GENERAL] Not Seeing Syntax Error

2011-08-17 Thread Rich Shepard
On Wed, 17 Aug 2011, David Johnston wrote: To be honest I was too and maybe I somehow implied that to you. Anyway, I believe if you are dealing with CSV import then you are correct but apparently SQL is not as forgiving. I use a third-party application to import my CSV usually so whether that

[GENERAL] INSERTing rows from external file

2011-08-16 Thread Rich Shepard
I have a file with 5500 rows formated as 'INSERT INTO table (column_names) VALUES values;' that I thought I could read using psql from the command line. However, the syntax, 'psql database_name filename.sql' throws an error at the beginning of the first INSERT statement. In the INSERT

Re: [GENERAL] INSERTing rows from external file

2011-08-16 Thread Rich Shepard
On Tue, 16 Aug 2011, Chris Travers wrote: What kind of error? Chris, Here's the full statement for the last row: psql:chem_too.sql:5517: ERROR: invalid input syntax for type boolean: LINE 1: ...NS','1996-11-21','Potassium','0.94988','mg/L','','','','...

Re: [GENERAL] INSERTing rows from external file

2011-08-16 Thread Rich Shepard
On Tue, 16 Aug 2011, Greg Smith wrote: Sounds like a problem with your file. Messing up CR/LF characters when moving things between Windows and UNIX systems is a popular one. Proof it works: Greg, Excel file imported into LibreOffice and converted to .ods. Columns marked and saved as

Re: [GENERAL] INSERTing rows from external file

2011-08-16 Thread Rich Shepard
On Tue, 16 Aug 2011, David Johnston wrote: Your INSERT statement is syntactically incorrect; the error has nothing to do with PSQL other than the fact that PSQL is reporting the error to you. David, I see that now. Odds are you are wrapping your Boolean input with single quotes and the

[GENERAL] Deleting Multiple Rows Based on Multiple Columns

2011-08-13 Thread Rich Shepard
Thanks to David J. I have a working script to locate multiple rows having the same values in three candidate columns. I used an enhanced version of this script to copy those duplicate (and triplicate) records to a clone of the original table. Now I would like to delete those duplicates from

Re: [GENERAL] [ADMIN] Using Postgresql as application server

2011-08-13 Thread Rich Shepard
On Sun, 14 Aug 2011, c k wrote: I would like to generate content dynamically. I want minimum developers to be required, simple and powerful security and administration, and most importantly ability to respond to changes. For my application the most important part is generating dynamic content.

Re: [GENERAL] COPY from .csv File and Remove Duplicates

2011-08-12 Thread Rich Shepard
On Thu, 11 Aug 2011, David Johnston wrote: If you have duplicates with matching real keys inserting into a staging table and then moving new records to the final table is your best option (in general it is better to do a two-step with a staging table since you can readily use Postgresql to

Re: [GENERAL] COPY from .csv File and Remove Duplicates

2011-08-12 Thread Rich Shepard
On Fri, 12 Aug 2011, David Johnston wrote: Select * From table Natural Inner join ( SELECT loc_name, sample_date, param, Count(*) as duplicate_count FROM table Group by loc_name, sample_date, param ) grouped Where duplicate_count 1 ; David, Thank you. I was close in my attempts, but not

Re: [GENERAL] COPY from .csv File and Remove Duplicates

2011-08-12 Thread Rich Shepard
On Fri, 12 Aug 2011, David Johnston wrote: Select * From table Natural Inner join ( SELECT loc_name, sample_date, param, Count(*) as duplicate_count FROM table Group by loc_name, sample_date, param ) grouped Where duplicate_count 1; Tried to use the above in an INSERT INTO statement to a

Re: [GENERAL] COPY from .csv File and Remove Duplicates [RESOLVED]

2011-08-12 Thread Rich Shepard
On Fri, 12 Aug 2011, David Johnston wrote: Thus, you need to replace the * in the SELECT with the specific columns that correspond to the columns listed in to INSERT portion of the query. David, Mea culpa! I should have seen this myself. Now the query works and I have about 6K duplicate

[GENERAL] Filling Missing Primary Key Values

2011-08-11 Thread Rich Shepard
I've a table (from a client, not created here) with a column that should be the primary key, but not all rows have a value for this attribute. The column format is VARCHAR(12) and has a variety of values, such as 96-A000672 and 9612-0881 (probably assigned by different analytical laboratories).

Re: [GENERAL] Filling Missing Primary Key Values

2011-08-11 Thread Rich Shepard
On Thu, 11 Aug 2011, Chris Travers wrote: The simplest seems to me to be a sequence and use nextval() to populate the null values. The major advantage would be that the sequence could stay around in case you need it again. So for example: create sequence my_varchar_values; UPDATE my_table

Re: [GENERAL] Filling Missing Primary Key Values

2011-08-11 Thread Rich Shepard
On Thu, 11 Aug 2011, Steve Atkins wrote: This will fail if any of the existing values are integers in the range that you're inserting - and it may fail in the future, as you add new records if they clash with existing entries. Steve/Chris/Dave: I had not looked in deatil at that column

[GENERAL] COPY from .csv File and Remove Duplicates

2011-08-11 Thread Rich Shepard
A table has a sequence to generate a primary key for inserted records with NULLs in that column. I have a .csv file of approximately 10k rows to copy into this table. My two questions which have not been answered by reference to my postgres reference book or Google searches are: 1) Will

Re: [GENERAL] suggestions for archive_command to a remote standby

2011-08-11 Thread Rich Shepard
On Thu, 11 Aug 2011, John DeSoi wrote: rsync seems to be suggested in a number of references for the archive_command when copying WAL files to another server. But the documentation states in bold letters that the command should refuse to overwrite existing files, *and that it returns nonzero

Re: [GENERAL] COPY from .csv File and Remove Duplicates

2011-08-11 Thread Rich Shepard
On Thu, 11 Aug 2011, David Johnston wrote: If you have duplicates with matching real keys inserting into a staging table and then moving new records to the final table is your best option (in general it is better to do a two-step with a staging table since you can readily use Postgresql to

[GENERAL] Add Foreign Keys To Table

2011-07-07 Thread Rich Shepard
I'm having difficulty finding the correct syntax to modify an existing table. The modification is to add two columns, each a foreign reference to the two key columns of another table. The other table: CREATE TABLE station_type ( sta_type VARCHAR(50), secondary_type VARCHAR(50),

Re: [GENERAL] Add Foreign Keys To Table

2011-07-07 Thread Rich Shepard
On Thu, 7 Jul 2011, Alan Hodgson wrote: You need a unique index on station_type.sta_type Alan, station_type(sta_type) is part of a composite primary key. Doesn't primary key automatically imply unique and not null? Thanks, Rich -- Sent via pgsql-general mailing list

Re: [GENERAL] Add Foreign Keys To Table

2011-07-07 Thread Rich Shepard
On Thu, 7 Jul 2011, Alan Hodgson wrote: It implies the composite is unique. Not sta_type. OK. Now I understand. How, then, do I add a unique constraint to each component of the composite key so I can add them as foreign keys to the station_information table? Or, is there another way to add

Re: [GENERAL] Add Foreign Keys To Table

2011-07-07 Thread Rich Shepard
On Thu, 7 Jul 2011, Alan Hodgson wrote: create unique index index_name on table (column). Alan, This worked like a charm. Many thanks for the lesson, Rich -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription:

Re: [GENERAL] Add Foreign Keys To Table

2011-07-07 Thread Rich Shepard
On Thu, 7 Jul 2011, John R Pierce wrote: Since your PK of station_type is a composite, your foreign key must also be composite. CREATE TABLE stuffed ( id serial; otherestuffs text; sta varchar(50), sec varchar(50), FOREIGN KEY (sta, sec) REFERENCES station_type(sta_type,

Re: [GENERAL] Add Foreign Keys To Table

2011-07-07 Thread Rich Shepard
On Thu, 7 Jul 2011, John R Pierce wrote: if your original table has Primary Key of (sta_type, secondary_type) I would not expect EITHER of those fields to be unique by themselves Surely there can be more than one of the same sta_type with different secondary_type's, just as there could be

[GENERAL] Adding Foreign Key Constraint To Existing Table

2011-07-01 Thread Rich Shepard
I've examined the 9.0 manual page on alter table without seeing how to add a foreign key constraint to a column. I needed to make changes on a couple of existing tables which could be accomplished only by dropping the foreign key constraint. That, and changing the table structure, column

Re: [GENERAL] Adding Foreign Key Constraint To Existing Table

2011-07-01 Thread Rich Shepard
On Fri, 1 Jul 2011, Joshua D. Drake wrote: alter table bar add foreign key (id) references foo(id); Thanks, Josh. I was close, but not exact. Rich -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription:

Re: [GENERAL] Adding Foreign Key Constraint To Existing Table

2011-07-01 Thread Rich Shepard
On Fri, 1 Jul 2011, Thom Brown wrote: By the way, rather than dropping the foreign key then recreating it, you could always do this: ALTER TABLE tablename DISABLE TRIGGER ALL; Then it would ignore the foreign key trigger and you could put in mischievous values... but remember to enable it

[GENERAL] DROP TABLE Appears to Fail

2011-06-28 Thread Rich Shepard
I cannot recall issuing a DROP TABLE command from psql that did not work, but seem to have this as a new experience. When I look at the database table list with '\d' I see public | station_type | table| rshepard public | station_type_statype_seq

Re: [GENERAL] DROP TABLE Appears to Fail

2011-06-28 Thread Rich Shepard
On Wed, 29 Jun 2011, Andy Firel wrote: it might be sufficient to add a semicolon to your drop statement: # drop table station_type; Andy, Actually, that's not true. On a whim I tried that and psql complained about a syntax error at the initial 'd'. Rich -- Sent via pgsql-general mailing

Re: [GENERAL] DROP TABLE Appears to Fail

2011-06-28 Thread Rich Shepard
On Tue, 28 Jun 2011, Rick Genter wrote: Silly question, but did you try it with a semicolon after the drop table? Rick, See my answer to Andy: that's incorrect syntax and psql complains. I've noticed that if you are in the middle of a statement and issue a \ command, psql ignores the SQL

Re: [GENERAL] DROP TABLE Appears to Fail [SOLVED]

2011-06-28 Thread Rich Shepard
On Tue, 28 Jun 2011, Rick Genter wrote: After issuing the \d you are still in the middle of your command. Witness the following copy/paste of a terminal session: Ah, so! I didn't see this. Thank you very much, Rich -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To

Re: [GENERAL] PHP and PostgreSQL 9.0, pg_connect fails to connect

2011-04-27 Thread Rich Shepard
On Wed, 27 Apr 2011, Thomas Harold wrote: Well, interestingly enough it is SELinux getting in the way, but not logging anything. Temporarily disabling SELinux suddenly makes it work. This is interesting. I don't run SElinux on my Slackware systems, but a PHP application (CMS Made Simple)

[GENERAL] Postgres-9.x - ADODB - PHP

2011-04-06 Thread Rich Shepard
My one PHP application stopped working since I upgraded postgres to -9.0.3. It uses the adodb interface. I can addess the postgres back end using psql. How do I determine if I need to update the adodb-php capabilities? And, what options should I have selected when building this version so

Re: [GENERAL] Postgres-9.x - ADODB - PHP

2011-04-06 Thread Rich Shepard
On Wed, 6 Apr 2011, Joshua D. Drake wrote: This seems more like a question for the adodb list. OK, Josh. Have you a URL for subscribing? Rich -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription:

Re: [GENERAL] Postgres-9.x - ADODB - PHP

2011-04-06 Thread Rich Shepard
On Wed, 6 Apr 2011, Rich Shepard wrote: Have you a URL for subscribing? Found one. Rich -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general

[GENERAL] Adding PK to Existing Table

2011-04-01 Thread Rich Shepard
In -9.0.3 I used ALTER TABLE to replace a varchar() column with a bigint column so it can be assigned as the table's primary key. From the 9.0.3 manual I tried various flavors of ALTER TABLE tablename ADD CONSTRAINT but cannot find the proper syntax to create the PK. Do I need to first make the

Re: [GENERAL] Adding PK to Existing Table [RESOLVED]

2011-04-01 Thread Rich Shepard
On Fri, 1 Apr 2011, Raghavendra wrote: Try out this... alter table table name add primary key(column name); Raghavendra, Aha! I missed noticing that I need parentheses around the column name. Much thanks, Rich -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make

[GENERAL] Post-Upgrade Question: 9.0.1 - 9.0.3

2011-03-10 Thread Rich Shepard
After carefully following the instructions here: http://www.postgresql.org/docs/9.0/static/install-upgrading.html I tested the upgrade from the command line. My question is why I still see a reference to 9.0.1; psql (9.0.1, server 9.0.3) Type help for help. One database was created

Re: [GENERAL] Post-Upgrade Question: 9.0.1 - 9.0.3

2011-03-10 Thread Rich Shepard
On Thu, 10 Mar 2011, Adrian Klaver wrote: Your psql binary is from 9.0.1 your server from 9.0.3. Somewhere you have the old psql in your path and it is being found first. Huh! Wonder how that happened. I moved /usr/local/pgsql/ to /usr/local/pgsql.9.0.1 and installed 9.0.3 into /usr/local.

Re: [GENERAL] Post-Upgrade Question: 9.0.1 - 9.0.3

2011-03-10 Thread Rich Shepard
On Thu, 10 Mar 2011, Adrian Klaver wrote: Your psql binary is from 9.0.1 your server from 9.0.3. Somewhere you have the old psql in your path and it is being found first. Adrian, Found it. There was an executable /bin/psql in addition to /usr/local/psql/bin/psql. I've no idea how the

Re: [GENERAL] Post-Upgrade Question: 9.0.1 - 9.0.3

2011-03-10 Thread Rich Shepard
On Thu, 10 Mar 2011, Adrian Klaver wrote: My guess is you did a Postgres client only package install at some point:) Not consciously. When I upgraded from 8.4 to 9.0.1 last December everything moved from /var/lib/pgsql to /usr/local/psql. The build/install date on the executable /bin/psql

<    1   2   3   4   5   6   >