Re: [GENERAL] Can I use a query with UPDATE on its SET?
Hi Ho! --- On Thu, 2/26/09, Craig Ringer cr...@postnewspapers.com.au wrote: Eus wrote: Hi Ho! Since I can do: INSERT INTO table (SELECT a_transaction.*); I am wondering whether I can do: UPDATE table SET (SELECT a_transaction.*) WHERE primary_key = (SELECT a_transaction.primary_key); UPDATE table SET fieldname = (SELECT ..) WHERE primary_key = (SELECT...) Is it possible to eliminate the use of `fieldname' completely? So, I just need to type `UPDATE table SET (SELECT ...) WHERE primary_key'. I think this should be possible because if the subquery in the SET clause returns the same number of columns with the same types of those of the destination table, PostgreSQL should be able to just update the values at once. Thanks. -- Craig Ringer Best regards, Eus (FSF member #4445) In this digital era, where computing technology is pervasive, your freedom depends on the software controlling those computing devices. Join free software movement today! It is free as in freedom, not as in free beer! Join: http://www.fsf.org/jf?referrer=4445 -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
[GENERAL] Can I use a query with UPDATE on its SET?
Hi Ho! Since I can do: INSERT INTO table (SELECT a_transaction.*); I am wondering whether I can do: UPDATE table SET (SELECT a_transaction.*) WHERE primary_key = (SELECT a_transaction.primary_key); instead of: DELETE FROM table WHERE primary_key = (SELECT a_transaction.primary_key); INSERT INTO table (SELECT a_transaction.*); Can I? I am using PostgreSQL 8.3.5. I get the feel that I cannot do so from reading the manual. Thank you. Best regards, Eus (FSF member #4445) In this digital era, where computing technology is pervasive, your freedom depends on the software controlling those computing devices. Join free software movement today! It is free as in freedom, not as in free beer! Join: http://www.fsf.org/jf?referrer=4445 -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
[GENERAL] PostgreSQL fast query is too slow as function
Hi Ho! The plain query runs for about 8.28 minutes. But, when the same query is put inside a function as follows: --- 8 --- create or replace function get_outgoing_transactions( area char(3), start_at timestamp with time zone, end_at timestamp with time zone) returns setof record as $$ begin return query ( -- the plain query -- ); end; $$ language plpgsql; --- 8 --- and called as follows: --- 8 --- select * from get_outgoing_transactions('sew' , '2008-05-30 00:00:00' , '2008-10-30 00:00:00' ) as (production_order_id character varying(15) , item_id integer , tag_id character varying(15) , color_abbrv_description character varying(15) , size_id character varying(10) , prev_grade character varying(10) , grade character varying(10) , audit_ts timestamp with time zone , from_area char(3) , into_area char(3) ) --- 8 --- it runs for about 21.50 minutes. I have read this blog: http://blog.endpoint.com/2008/12/why-is-my-function-slow.html, and therefore, I ran each case two times. The running times that I write above were taken from the second run of each case, which is always shorter than the first run. As described in the blog, I also have tried to find out whether or not a different query plan is used as follows: --- 8 --- prepare foobar(char(3) , timestamp with time zone , timestamp with time zone) as -- the plain query -- ; explain execute foobar('sew' , '2008-05-30 00:00:00' , '2008-10-30 00:00:00'); --- 8 --- The query plan is just the same with `explain -- the plain query --' with a difference that the plain query has castings on the plain parameters. I thought the bottle neck was in the use of `returns setof record'. But, changing it to just return the table does not change the situtation. Any idea as to how I should attack this problem? Thank you. Best regards, Eus (FSF member #4445) In this digital era, where computing technology is pervasive, your freedom depends on the software controlling those computing devices. Join free software movement today! It is free as in freedom, not as in free beer! Join: http://www.fsf.org/jf?referrer=4445 -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
[GENERAL] Why I cannot call a function from within an SQL function?
Hi Ho! The following query works well: select count (*) from item_audit where audit_ts = '2008-05-30 00:00:00' and audit_ts = '2008-10-30 00:00:00' and 'wst' != (select split_part(category, '-', 2) from description where split_part(category, '-', 1) = 'item' and shorthand = status ) But, when I transform it into the following SQL function, the function cannot be created barking: ERROR: syntax error at or near - LINE 6:and $1 != (select split_part(category, '-', 2) create or replace function get_I(text, timestamp, timestamp) returns bigint as 'select count (*) from item_audit as ia where audit_ts = $2 and audit_ts = $3 and $1 != (select split_part(category, '-', 2) from description where split_part(category, '-', 1) = 'item' and shorthand = ia.status ) ' language sql; What's wrong? Thank you. Best regards, Eus (FSF member #4445) In this digital era, where computing technology is pervasive, your freedom depends on the software controlling those computing devices. Join free software movement today! It is free as in freedom, not as in free beer! Join: http://www.fsf.org/jf?referrer=4445 -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] Why I cannot call a function from within an SQL function?
Hi Ho! Sorry, let me revise the query a bit. I copied and pasted the original one from another big query. --- On Fri, 2/20/09, Eus e...@member.fsf.org wrote: The following query works well: select count (*) from item_audit as ia where audit_ts = '2008-05-30 00:00:00' and audit_ts = '2008-10-30 00:00:00' and 'wst' != (select split_part(category, '-', 2) from description where split_part(category, '-', 1) = 'item' and shorthand = ia.status ) But, when I transform it into the following SQL function, the function cannot be created barking: ERROR: syntax error at or near - LINE 6:and $1 != (select split_part(category, '-', 2) create or replace function get_I(text, timestamp, timestamp) returns bigint as 'select count (*) from item_audit as ia where audit_ts = $2 and audit_ts = $3 and $1 != (select split_part(category, '-', 2) from description where split_part(category, '-', 1) = 'item' and shorthand = ia.status ) ' language sql; What's wrong? Thank you. Best regards, Eus (FSF member #4445) In this digital era, where computing technology is pervasive, your freedom depends on the software controlling those computing devices. Join free software movement today! It is free as in freedom, not as in free beer! Join: http://www.fsf.org/jf?referrer=4445 -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] Why I cannot call a function from within an SQL function?
Hi Ho! --- On Fri, 2/20/09, Miguel Ángel MF michelangel...@gmail.com wrote: I'm no expert, but: i might say U should Escape the ` ' ´ char in (select split_part(category, '-', 2) using something like (select split_part(category, \'-\', 2) or however it should be... Yes, you are right! Thank you for telling me this. I had been looking for this information for half an hour. A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail? http://www.brainyquote.com/quotes/authors/m/muhammad_ali.html http://www.brainyquote.com/quotes/authors/e/emma_goldman.html http://www.brainyquote.com/quotes/authors/m/michelangelo.html Bill Watterson - There is not enough time to do all the nothing we want to do. Best regards, Eus (FSF member #4445) In this digital era, where computing technology is pervasive, your freedom depends on the software controlling those computing devices. Join free software movement today! It is free as in freedom, not as in free beer! Join: http://www.fsf.org/jf?referrer=4445 -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] Why I cannot call a function from within an SQL function?
Hi Ho! --- On Fri, 2/20/09, A. Kretschmer andreas.kretsch...@schollglas.com wrote: In response to Eus : Hi Ho! The following query works well: select count (*) from item_audit where audit_ts = '2008-05-30 00:00:00' and audit_ts = '2008-10-30 00:00:00' and 'wst' != (select split_part(category, '-', 2) from description where split_part(category, '-', 1) = 'item' and shorthand = status ) But, when I transform it into the following SQL function, the function cannot be created barking: ERROR: syntax error at or near - LINE 6:and $1 != (select split_part(category, '-', 2) create or replace function get_I(text, timestamp, timestamp) returns bigint as 'select count (*) from item_audit as ia where audit_ts = $2 and audit_ts = $3 and $1 != (select split_part(category, '-', 2) from description where split_part(category, '-', 1) = 'item' and shorthand = ia.status ) ' language sql; What's wrong? The quoting. Use $$-quoting around the function, for instance: create or replace function get_I(text, timestamp, timestamp) returns bigint as $$ select count (*) ... $$ language plpgsql; Now you can use simple ' inside the function. Other, but inferior solution, use ''' instead ' inside the function. Wow, this is great! Now I know the use of `$$'. Does the doc tell this? If yes, I really have missed it. Thank you very much for telling me this. You have saved me a lot of time from quoting a bunch of text. HTH, Andreas Yes, it really helps. Thank you very much. -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net Best regards, Eus (FSF member #4445) In this digital era, where computing technology is pervasive, your freedom depends on the software controlling those computing devices. Join free software movement today! It is free as in freedom, not as in free beer! Join: http://www.fsf.org/jf?referrer=4445 -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] Why I cannot call a function from within an SQL function?
Hi Ho! --- On Fri, 2/20/09, Ketema Harris ket...@ketema.net wrote: Use dollar quoting around your fiction body I'd double up on the single quotes around the dash Yup, I got it. Thank you for your help. Sent from my iPhone Best regards, Eus (FSF member #4445) In this digital era, where computing technology is pervasive, your freedom depends on the software controlling those computing devices. Join free software movement today! It is free as in freedom, not as in free beer! Join: http://www.fsf.org/jf?referrer=4445 -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] Why I cannot call a function from within an SQL function?
Hi Ho! --- On Fri, 2/20/09, Marc Schablewski m...@clickware.de wrote: You are using old-style function declaration where the function body is given as a string enclosed in '. You have to escape all ' inside the body by doubling them. Ah, yes, after re-reading the doc, I found: --- 8 --- The syntax of the CREATE FUNCTION command requires the function body to be written as a string constant. It is usually most convenient to use dollar quoting (see Section 4.1.2.2) for the string constant. If you choose to use regular single-quoted string constant syntax, you must double single quote marks (') and backslashes (\) (assuming escape string syntax) in the body of the function (see Section 4.1.2.1). --- 8 --- I really missed it. Sorry for making noise. As an alternative, you can use $$ as the begin and end markers of your function body instead of the ' then you don't need to escape. Yes, this is much better. Thank you very much for your explanation. Best regards, Eus (FSF member #4445) In this digital era, where computing technology is pervasive, your freedom depends on the software controlling those computing devices. Join free software movement today! It is free as in freedom, not as in free beer! Join: http://www.fsf.org/jf?referrer=4445 -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] Check for an empty result
Hi Craig! --- On Fri, 2/13/09, Craig Ringer cr...@postnewspapers.com.au wrote: Eus wrote: Hi Ho! Is there a way to check whether or not a subquery returns an empty result set? EXISTS SELECT blah FROM blah WHERE EXISTS (SELECT 1 FROM tablename WHERE ...); Thank you. Previously I tried: ... WHERE (...) IS NULL;. Of course, it didn't work. postgre check empty result set It's not postgre. It's PostgreSQL, or postgres. This matters when you're searching. Oh, okay. Thanks for telling me. -- Craig Ringer Best regards, Eus (FSF member #4445) In this digital era, where computing technology is pervasive, your freedom depends on the software controlling those computing devices. Join free software movement today! It is free as in freedom, not as in free beer! Join: http://www.fsf.org/jf?referrer=4445 -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] Check for an empty result
Hi Andreas! --- On Fri, 2/13/09, A. Kretschmer andreas.kretsch...@schollglas.com wrote: In response to Eus : Hi Ho! Is there a way to check whether or not a subquery returns an empty result set? You can use EXISTS for that: -- empty result test=*# select * from (select 1 where 1=2) foo; ?column? -- (0 rows) That's good that it can be used in FROM phrase too besides WHERE phrase. -- check if a result exists test=*# select exists(select * from (select 1 where 1=2) foo); ?column? -- f (1 row) test=*# select exists(select * from (select 1 where 1=1) foo); ?column? -- t (1 row) Even in SELECT phrase? That's great! Thank you for the information. Regards, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net Best regards, Eus (FSF member #4445) In this digital era, where computing technology is pervasive, your freedom depends on the software controlling those computing devices. Join free software movement today! It is free as in freedom, not as in free beer! Join: http://www.fsf.org/jf?referrer=4445 -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
[GENERAL] Check for an empty result
Hi Ho! Is there a way to check whether or not a subquery returns an empty result set? Googling with the following keywords does not help: postgre check empty result set sql check empty result Thank you. Best regards, Eus (FSF member #4445) In this digital era, where computing technology is pervasive, your freedom depends on the software controlling those computing devices. Join free software movement today! It is free as in freedom, not as in free beer! Join: http://www.fsf.org/jf?referrer=4445 -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] Using database to find file doublettes in my computer
Hi Ho! --- On Tue, 11/18/08, Lothar Behrens [EMAIL PROTECTED] wrote: Hi, I have a problem to find as fast as possible files that are double or in other words, identical. Also identifying those files that are not identical. My approach was to use dir /s and an awk script to convert it to a sql script to be imported into a table. That done, I could start issuing queries. But how to query for files to display a 'left / right view' for each file that is on multible places ? I mean this: This File;Also here C:\some.txt;C:\backup\some.txt C:\some.txt;C:\backup1\some.txt C:\some.txt;C:\backup2\some.txt but have only this list: C:\some.txt C:\backup\some.txt C:\backup1\some.txt C:\backup2\some.txt The reason for this is because I am faced with the problem of ECAD projects that are copied around many times and I have to identify what files are here missing and what files are there. So a manual approach is as follows: 1) Identify one file (schematic1.sch) and see, where are copies of it. 2) Compare the files of both directories and make a desision about what files to use further. 3) Determine conflicts, thus these files can't be copied together for a cleanup. Are there any approaches or help ? I also have been in this kind of circumstance before, but I work under GNU/Linux as always. 1. At that time, I used `md5sum' to generate the fingerprint of all files in a given directory to be cleaned up. 2. Later, I created a simple Java program to group the names of all files that had the same fingerprint (i.e., MD5 hash). 3. I simply deleted the files with the same MD5 hash but one file with a good filename (in my case, the filename couldn't be relied on to perform a comparison since it differed by small additions like date, author's name, and the like). 4. After that, I used my brain to find related files based on the filenames (e.g., `[2006-05-23] Jeff - x.txt' should be the same as `Jenny - x.txt'). Of course, the Java program also helped me in grouping the files that I thought to be related. 5. Next, I perused the related files to see whether most of the contents were the same. If yes, I took the latest one based on the modified time. This is a very time consuming job and I am searching for any solution that helps me save time :-) Well, I think I saved a lot of time at that time to be able to eliminate about 7,000 files out of 15,000 files in about two weeks. I know that those problems did not arise when the projects are well structured and in a version management system. But that isn't here :-) I hope you employ such a system ASAP :-) Thanks Lothar Best regards, Eus (FSF member #4445) In this digital era, where computing technology is pervasive, your freedom depends on the software controlling those computing devices. Join free software movement today! It is free as in freedom, not as in free beer! Join: http://www.fsf.org/jf?referrer=4445 -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] how to group several records with same timestamp into one line?
Hi Ho! --- On Thu, 11/13/08, Brent Wood [EMAIL PROTECTED] wrote: You need to use a self relation, not a group by, as no data are being aggregated into a new single value, which is what the group by achieves. This joins a table to itself, so that columns in it can be replicated. The key is that the where clause in each case needs to just select one channel, so it acts like a similar table but contains different rows. Because you used a char() instead of varchar() for channel, you may find your string 'channel1' has spaces in it to pad it to the specified length, in which case the where clauses below can use like '%channel1%' instead of = 'channel1' or you can strip the spaces before the comparison, eg: where trim(a.channel)='channel1'. I hope this makes sense. eg: select a.data, a.unit, b.data, b.unit, c.data, c.unit, d.data, d.unit, a.create_on from record data a, record-data b, record_data c, record_data d where a.channel='channel1' and b.channel='channel2' and c.channel='channel3' and d.channel=channel4 and b.create_on = a.create_on and c.create_on = a.create_on and d.create_on = a.create on; Thus table a comprises all records from channel1, etc... and they are joined on a common timestamp. NOTE: if any of the channels are null for any given timestamp, you will get no record for that timestamp using this syntax, even if other channels had data, because the query uses an inner join. If this is a problem then you'll need to reword the query as an outer join. Isn't that something like this is better handled at the application level instead of the DB level? IOW, isn't that the cost of doing the query above far more expensive than doing a little coding at the application level? May I know your opinion? Thanks. HTH, Brent Wood Brent Wood DBA/GIS consultant NIWA, Wellington New Zealand Best regards, Eus (FSF member #4445) In this digital era, where computing technology is pervasive, your freedom depends on the software controlling those computing devices. Join free software movement today! It is free as in freedom, not as in free beer! Join: http://www.fsf.org/jf?referrer=4445 -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
[GENERAL] Why Postgresql Public Schema Is Not Owned By The DB Owner By Default
Hi Ho! As a new user of Postgresql 8.3.3, I came across this common error message when restoring a database previously dumped from another machine: 15: ERROR: must be owner of schema public when it came to this line in the dump file: COMMENT ON SCHEMA public IS 'Standard public schema'; And, also the following warning messages: 193842: WARNING: no privileges could be revoked for public 193843: WARNING: no privileges could be revoked for public 193844: WARNING: no privileges were granted for public 193845: WARNING: no privileges were granted for public 193846: WARNING: no privileges were granted for public For the following lines in the dump file: REVOKE ALL ON SCHEMA public FROM PUBLIC; REVOKE ALL ON SCHEMA public FROM my_role_1; GRANT ALL ON SCHEMA public TO my_role_1; GRANT ALL ON SCHEMA public TO PUBLIC; GRANT USAGE ON SCHEMA public TO my_role_2; All of which can be solved when the schema public is owned by the owner of the DB, which is my_role_1, by issuing: ALTER SCHEMA public OWNER TO my_role_1; So, the question is: Why does Postgresql by default assign the ownership of the public schema of a DB to postgres instead of the owner of the DB itself? What does it entail when by default the ownership of the public schema is given to the owner of the DB (from security or other aspects)? I have researched the archive of the mailing list with the following result: 1. http://archives.postgresql.org/pgsql-general/2008-04/msg00714.php The same question was raised here, but not answered. 2. http://archives.postgresql.org/pgsql-admin/2008-01/msg00128.php One had a work-around by temporarily making the owner of the DB become SUPERUSER. 3. http://archives.postgresql.org/pgsql-hackers/2008-01/msg00462.php One tried to suppress the error message related to `COMMENT ON SCHEMA public IS 'Standard public schema';' But, they do not answer my question. So, can someone provide me with the answers to the questions? Particularly, what does it entail when by default the ownership of the public schema is given to the owner of the DB (from security or other aspects)? Thank you very much. Best regards, Eus -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] Why Postgresql Public Schema Is Not Owned By The DB Owner By Default
Hi Ho! --- On Thu, 10/30/08, Tom Lane [EMAIL PROTECTED] wrote: Because it'd be extremely difficult to do otherwise (given the way that CREATE DATABASE works) Understood. and it's not at all clear that it'd be a good idea anyway. Can it be cleared up by looking at the kind of security breaches that can be abused by users that are not the owner of the DB when the public schema is owned by the owner of the DB (i.e., not a SUPERUSER) instead of by postgres? I am hoping to get a list of achilles' heels that I need to consider when assigning the ownership of a public schema of a DB to its owner that is not a SUPERUSER from the default postgres. regards, tom lane Best regards, Eus -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general