Re: [SQL] Question about index/constraint definition in a table

2013-10-09 Thread David Johnston
David Johnston wrote > > JORGE MALDONADO wrote >> I have a table as follows: >> >> Table Artist Colaborations >> >> * car_id (integer field, primary key) >&

Re: [SQL] Question about index/constraint definition in a table

2013-10-09 Thread David Johnston
JORGE MALDONADO wrote > I have a table as follows: > > Table Artist Colaborations > > * car_id (integer field, primary key) > * car_song (integer field, foreign key, foreign table is a catalog of > son

Re: [SQL] Unique index VS unique constraint

2013-10-04 Thread David Johnston
Steve Grey-2 wrote > Unique indexes can be partial, i.e. defined with a where clause (that must > be included in a query so that PostgreSQL knows to use that index) whereas > unique constraints cannot. This implies there can be data in the table but not in the index and thus said index is not part

Re: [SQL] Advice on defining indexes

2013-10-04 Thread David Johnston
JORGE MALDONADO wrote > If a table has a foreign key on 2 fields, should I also create an index > composed of such fields? Yes. If you want to truly/actually model a foreign key the system will require you to create a unique constraint/index on the "primary/one" side of the relationship. CREATE

Re: [SQL] Unique index VS unique constraint

2013-10-04 Thread David Johnston
JORGE MALDONADO wrote > I have search for information about the difference between "unique index" > and "unique constraint" in PostgreSQL without getting to a specific > answer, > so I kindly ask for an explanation that helps me clarify such concept. A constraint says what valid data looks like.

Re: [SQL] Advice on defining indexes

2013-10-04 Thread David Johnston
JORGE MALDONADO wrote > I have a table with fields that I guess would be a good idea to set as > indexes because users may query it to get results ordered by different > criteria. For example: > > -- > Artists Table > -- > 1. art_id > 2. art_name > 3. art_bday > 4.

Re: [SQL] Help needed with Window function

2013-10-02 Thread David Johnston
gmb wrote > item_code | _date| qty | max > - > ABC | 2013-04-05 | 10.00| 2013-04-05 > ABC | 2013-04-06 | 10.00| 2013-04-06 > ABC | 2013-04-06 | -2.00| 2013-04-06

Re: [SQL] postgres subfunction return error

2013-09-27 Thread David Johnston
jonathansfl wrote > SELECT * INTO v_outvar1, v_outvar2, v_outvar3 FROM > custom.pr_test_subfunction(SWV_Action); > OPEN swv_refcur for SELECT v_outvar1; > OPEN swv_refcur2 for SELECT v_outvar2; > OPEN swv_refcur3 for SELECT v_outvar3; > RETURN; I've never used cursors in this

Re: [SQL] postgres subfunction return error

2013-09-25 Thread David Johnston
jonathansfl wrote > greetings. I'm trying to write a function that acts like a switchboard, > calling other functions depending on incoming parameters. > I'm getting error: query has no destination for result data > > > SELECT * FROM dev.pr_test_subfunction(SWV_Action); In pl/pgsql if you

Re: [SQL] removing duplicates and using sort

2013-09-16 Thread David Johnston
Note that you could always do something like: WITH original_query AS ( SELECT DISTINCT ... ) SELECT * FROM original_query ORDER BY lastname, firstname; OR SELECT * FROM ( SELECT DISTINCT ) sub_query ORDER BY lastname, firstname I am thinking you cannot alter the existing ORDER BY other

Re: [SQL] Using regexp_matches in the WHERE clause

2013-08-29 Thread David Johnston
spulatkan wrote > so following is enough to get the rows that matches regular expression > This is bad form even if it works. If the only point of the expression is to filter rows it should appear in the WHERE clause. The fact that regexp_matches(...) behaves in this way at all is, IMO, a flaw

Re: [SQL] Criteria to define indexes

2013-07-26 Thread David Johnston
JORGE MALDONADO wrote > And so on. What I see is that it is not a good decision to set a key for > every possibility because it will have an impact on performance due to > index maintenance. What would be a good way to define indexes in a case > like this? For your specific case, and also more gen

Re: [SQL] Update a composite nested type variable

2013-07-08 Thread David Johnston
Luca Vernini wrote > 2013/7/8 David Johnston < > polobo@ > > > >> >> This may be a pl/pgsql limitation but you should probably provide a >> complete >> self-contained example with your attempt so that user-error can be >> eliminated. >>

Re: [SQL] Update a composite nested type variable

2013-07-08 Thread David Johnston
Luca Vernini wrote > I'm writing a system with havy use of composite types. > I have a doubt. > > I'm writing all in functions with language plpgsql. > When I read a field from a composite type I must write something like > this: > status = ((in_customer.customer_data).customer_status).status_id >

Re: [SQL] UNNEST result order vs Array data

2013-06-20 Thread David Johnston
gmb wrote >>> The best, which you won't >>> like, is to wait for 9.4 where unnest() will most likely have a WITH >>> ORDINALITY option and you can sort on that. > > The fact that this type of thing is on the 9.4 roadmap indicates (to me, > in any case) that there are problems with the UNNEST f

Re: [SQL] Select statement with except clause

2013-05-24 Thread David Johnston
Reply-all is acceptable; but standard list protocol is to respond at the end of the message after performing "quote editing". JORGE MALDONADO wrote > Firstly, I want to thank you for responding. > Secondly, I wonder if I should only reply to the mailing list (I clicked > Reply All); if this is th

Re: [SQL] Select statement with except clause

2013-05-23 Thread David Johnston
JORGE MALDONADO wrote > How does the EXCEPT work? Do fields should be identical? > I need the difference to be on the first 3 fields. Except operates over the entire tuple so yes all fields are evaluated and, if they all match, the row from the "left/upper" query is excluded. If you need somethin

Re: [SQL] pivot query with count

2013-04-12 Thread David Johnston
My prior comment simply answers your question. You likely can rewrite your query so that a separate grouping layer is not needed (or rather the group by would exist in the main query and you minimize the case/sub-select column queries and use aggregates and case instead). David J. -- View th

Re: [SQL] pivot query with count

2013-04-12 Thread David Johnston
SELECT num_ads, sum(...), sum(...), FROM ( your query here ) GROUP BY num_ads; BTW, While "SELECT '1' "num_ads" is valid syntax I recommend you use the "AS" keyword. '1' AS "num_ads" David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/pivot-query-with-cou

Re: [SQL] Query execution based on a condition

2012-12-29 Thread David Johnston
From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of JORGE MALDONADO Sent: Saturday, December 29, 2012 2:06 PM To: pgsql-sql@postgresql.org Subject: [SQL] Query execution based on a condition I have a query similar to the one shown below but, depending on th

Re: [SQL] deciding on one of multiple results returned

2012-12-21 Thread David Johnston
From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Wes James Sent: Friday, December 21, 2012 11:32 AM To: pgsql-sql@postgresql.org Subject: [SQL] deciding on one of multiple results returned If a query returns, say the following results: id value 0

Re: [SQL] Joining several rows into only one

2012-11-28 Thread David Johnston
> -Original Message- > From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql- > ow...@postgresql.org] On Behalf Of Oliver d'Azevedo Cristina > Sent: Wednesday, November 28, 2012 1:42 PM > To: JORGE MALDONADO > Cc: pgsql-sql@postgresql.org > Subject: Re: [SQL] Joining several rows into only

Re: [SQL] Using regexp_matches in the WHERE clause

2012-11-27 Thread David Johnston
On Nov 26, 2012, at 7:13, Thomas Kellerer wrote: > > So I tried: > > SELECT * > FROM some_table > WHERE regexp_matches(somecol, 'foobar') is not null; > > However that resulted in: ERROR: argument of WHERE must not return a set > > Hmm, even though an array is not a set I can partly see

Re: [SQL] replace text occurrences loaded from table

2012-10-30 Thread David Johnston
> -Original Message- > From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql- > ow...@postgresql.org] On Behalf Of jan zimmek > Sent: Tuesday, October 30, 2012 7:45 AM > To: pgsql-sql@postgresql.org > Subject: [SQL] replace text occurrences loaded from table > > hello, > > i am actually

Re: [SQL] pull in most recent record in a view

2012-10-28 Thread David Johnston
On Oct 26, 2012, at 5:24, Gary Stainburn wrote: > This is my best effort so far is below. My concern is that it isn't very > efficient and will slow down as record numbers increase > > create view current_qualifications as > select q.*, (q.qu_qualified+q.qu_renewal)::date as qu_expires from >

Re: [SQL] Insert strings that contain colons into a table

2012-10-19 Thread David Johnston
> -Original Message- > From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql- > ow...@postgresql.org] On Behalf Of lmagnell > Sent: Friday, October 19, 2012 4:25 PM > To: pgsql-sql@postgresql.org > Subject: [SQL] Insert strings that contain colons into a table > > How can I insert multipl

Re: [SQL] Trigger triggered from a foreign key

2012-10-19 Thread David Johnston
> -Original Message- > From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql- > ow...@postgresql.org] On Behalf Of Victor Sterpu > Sent: Friday, October 19, 2012 2:15 PM > To: pgsql-sql@postgresql.org > Subject: [SQL] Trigger triggered from a foreign key > > I have this trigger that works

Re: [SQL] How to make this CTE also print rows with 0 as count?

2012-10-06 Thread David Johnston
> -Original Message- > From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql- > ow...@postgresql.org] On Behalf Of air > Sent: Saturday, October 06, 2012 8:48 AM > To: pgsql-sql@postgresql.org > Subject: [SQL] How to make this CTE also print rows with 0 as count? > > I have a CTE based qu

Re: [SQL] String Search

2012-10-04 Thread David Johnston
> -Original Message- > From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql- > ow...@postgresql.org] On Behalf Of Fabio Ebner - Dna Solution > Sent: Thursday, October 04, 2012 3:41 PM > To: pgsql-sql@postgresql.org > Subject: [SQL] String Search > > Anyone know the best way to do one sel

Re: [SQL] Calling the CTE for multiple inputs

2012-10-04 Thread David Johnston
> -Original Message- > From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql- > ow...@postgresql.org] On Behalf Of air > Sent: Thursday, October 04, 2012 3:32 PM > To: pgsql-sql@postgresql.org > Subject: [SQL] Calling the CTE for multiple inputs > > I have a CTE that takes top left and bo

Re: [SQL] Help in accessing array

2012-10-02 Thread David Johnston
> -Original Message- > From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql- > ow...@postgresql.org] On Behalf Of mephysto > Sent: Thursday, September 27, 2012 6:12 AM > To: pgsql-sql@postgresql.org > Subject: [SQL] Help in accessing array > > Hi to everyone, > I have a little problem to

Re: [SQL] [noob] How to optimize this double pivot query?

2012-10-01 Thread David Johnston
t; > Are there other better options worth considering that you could point me > towards that supports storing metrics viz. with an unbounded number of metric > types in my case? > > Bob > > On Mon, Oct 1, 2012 at 9:07 PM, David Johnston wrote: > From: pgsql-sql-ow

Re: [SQL] [noob] How to optimize this double pivot query?

2012-10-01 Thread David Johnston
From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Robert Buck Sent: Monday, October 01, 2012 8:47 PM To: pgsql-sql@postgresql.org Subject: [SQL] [noob] How to optimize this double pivot query? I have two tables that contain key-value data that I want to

Re: [SQL] Reuse temporary calculation results in an SQL update query [SOLVDED]

2012-09-30 Thread David Johnston
> > thank you. The "WITH" clause did the trick. I did not even know that such a > thing exists. But as it turns out it makes the statement more readable and > elegant but not faster. > > The reason for the latter is that both the CTE and the UPDATE statement > have the same "FROM ... WHERE ..." p

Re: [SQL] Need help with a special JOIN

2012-09-29 Thread David Johnston
On Sep 29, 2012, at 12:02, Andreas wrote: > Hi, > > asume I've got 2 tables > > objects ( id int, name text ) > attributes ( object_id int, value int ) > > attributes has a default entry with object_id = 0 and some other where > another value should be used. > > e.g. > objects > ( 1, '

Re: [SQL] Reuse temporary calculation results in an SQL update query

2012-09-29 Thread David Johnston
On Sep 29, 2012, at 6:49, Matthias Nagel wrote: > Hello, > > is there any way how one can store the result of a time-consuming calculation > if this result is needed more than once in an SQL update query? This solution > might be PostgreSQL specific and not standard SQL compliant. Here is an

Re: [SQL]

2012-09-22 Thread David Johnston
On Sep 22, 2012, at 20:15, JORGE MALDONADO wrote: > I have the following query: > > SELECT > sem_clave, > to_char(secc_esp_media.sem_fechareg,'TMMon-DD-') as sem_fechareg, > sem_seccion, > sem_titulo, > sem_enca, > tmd_nombre, > tmd_archivo, > tmd_origen, > gen_nombre, > smd_nombre, > prm_ur

Re: [SQL] ERROR: missing FROM-clause entry for table "new"

2012-09-13 Thread David Johnston
On Sep 13, 2012, at 20:40, James Sharrett wrote: > I'm trying to define a trigger function that looks for changes in table A > (table the trigger for the function is on) and write a delta record into > table B. So if a record has a value of 100 in table A, and it is updated to > 50, the funct

Re: [SQL] Query with LIMIT clause

2012-09-09 Thread David Johnston
osed of both initial > and final date? > > Regards, > Jorge Maldonado > > On Sun, Sep 9, 2012 at 12:45 PM, David Johnston wrote: > From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] > On Behalf Of JORGE MALDONADO > Sent: Sunday, September

Re: [SQL] Query with LIMIT clause

2012-09-09 Thread David Johnston
From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of JORGE MALDONADO Sent: Sunday, September 09, 2012 1:26 PM To: pgsql-sql@postgresql.org Subject: [SQL] Query with LIMIT clause I have the following records that I get from a query, the fields are date type in d

Re: [SQL] returning values to variables from dynamic SQL

2012-09-08 Thread David Johnston
>> From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of James Sharrett Sent: Saturday, September 08, 2012 6:24 PM To: pgsql-sql@postgresql.org Subject: [SQL] returning values to variables from dynamic SQL I have a PG function ( u

Re: [SQL] Need to Iterate the record in plpgsql

2012-09-06 Thread David Johnston
Yelai, The etiquette on this list is to place all replies either in-line (but following the content being quoted) or at the end of the posting. My reply is at the end. =By: Sergey Konoplev If you do not need information about column types you can use hstore for this purpose. [local]

Re: [SQL] prepared statement in crosstab query

2012-08-31 Thread David Johnston
On Aug 31, 2012, at 21:53, Samuel Gendler wrote: > I have the following crosstab query, which needs to be parameterized in the 2 > inner queries: > > SELECT * FROM crosstab( > $$ > SELECT t.local_key, >s.sensor_pk, >CASE WHEN t.local_day_abbreviation IN (?,?,?,?,?,

Re: [SQL] Error: Template Id should be teh identifier of a template - help

2012-08-17 Thread David Johnston
From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Alex Sent: Friday, August 17, 2012 11:58 AM To: pgsql-sql@postgresql.org Subject: [SQL] Error: Template Id should be teh identifier of a template - help Hi, All! When I execute this: UPDATE HTMLPAGE SET PA

Re: [SQL] [GENERAL] Indexing question

2012-08-15 Thread David Johnston
> -Original Message- > From: pgsql-general-ow...@postgresql.org [mailto:pgsql-general- > ow...@postgresql.org] On Behalf Of amit sehas > Sent: Tuesday, August 14, 2012 12:55 PM > To: pgsql-sql@postgresql.org; pgsql-gene...@postgresql.org > Subject: [GENERAL] Indexing question > > In SQL, g

Re: [SQL] join against a function-result fails

2012-07-27 Thread David Johnston
On Jul 27, 2012, at 21:57, Andreas wrote > Hi, > I have a table with user ids and names. > Another table describes some rights of those users and still another one > describes who inherits rights from who. > > A function all_rights ( user_id ) calculates all rights of a user recursively > and

Re: [SQL] query two tables using same lookup table

2012-07-22 Thread David Johnston
On Jul 22, 2012, at 23:04, ssylla wrote: > Dear list, > > assuming I have two tables as follows > > t1: > id_project|id_auth > 1|1 > 2|2 > > t2: > id_project|id_auth > 1|2 > 2|1 > > > and a lookup-table: > > t3 > id_auth|name_auth > 1|name1 > 2|name2 > > Now I want to query

Re: [SQL] Prevent double entries ... no simple unique index

2012-07-12 Thread David Johnston
On Jul 12, 2012, at 4:44, Andreas wrote: > Am 12.07.2012 07:14, schrieb Andreas Kretschmer: >> Marc Mamin wrote: >> >>> A partial index would do the same, but requires less space: >>> >>> create unique index on log(state) WHERE state IN (0,1); >> > > > OK, nice :) > > What if I have thos

Re: [SQL] How to solve the old bool attributes vs pivoting issue?

2012-06-27 Thread David Johnston
On Jun 27, 2012, at 21:07, Andreas wrote: > Hi > > I do keep a table of objects ... let's say companies. > > I need to collect flags that express yes / no / don't know. > > TRUE / FALSE / NULL would do. > > > Solution 1: > I have a boolean column for every flag within the companies-table.

Re: [SQL] Need help building this query

2012-06-21 Thread David Johnston
> -Original Message- > From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql- > ow...@postgresql.org] On Behalf Of Rihad > Sent: Thursday, June 21, 2012 1:49 PM > To: pgsql-sql@postgresql.org > Subject: [SQL] Need help building this query > > Hi, folks. I currently need to join two tables

Re: [SQL] using ordinal_position

2012-06-07 Thread David Johnston
> -Original Message- > From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql- > ow...@postgresql.org] On Behalf Of John Fabiani > Sent: Thursday, June 07, 2012 7:18 PM > To: pgsql-sql@postgresql.org > Subject: [SQL] using ordinal_position > > I'm attempting to retrieve data using a select

Re: [SQL] defaults in a function

2012-06-06 Thread David Johnston
On Jun 6, 2012, at 11:08, John Fabiani wrote: > Hi, > In python when I create a method/function is set a default value for a passed > value if one is not provided. > > def foo(self, event = None): > > In the above function if the second value is not passed a value of None is > used as the def

Re: [SQL] Lowest 2 items per

2012-06-01 Thread David Johnston
On Jun 1, 2012, at 10:34, "Relyea, Mike" wrote: > I need a little help putting together a query. I have the tables listed > below and I need to return the lowest two consumables (ranked by cost > divided by yield) per printer, per color of consumable, per type of > consumable. > > CREATE TABLE

Re: [SQL] Finding Max Value in a Row

2012-05-11 Thread David Johnston
> -Original Message- > From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql- > ow...@postgresql.org] On Behalf Of Carlos Mennens > Sent: Friday, May 11, 2012 3:04 PM > To: PostgreSQL (SQL) > Subject: [SQL] Finding Max Value in a Row > > I have a problem in SQL I don't know how to solve a

Re: [SQL] generic crosstab ?

2012-04-24 Thread David Johnston
From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Andreas Sent: Tuesday, April 24, 2012 5:35 PM To: Samuel Gendler Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] generic crosstab ? Am 24.04.2012 22:08, schrieb Samuel Gendler: On Tue, Apr 24, 2012 at

Re: [SQL] Wrong output from union

2012-03-30 Thread David Johnston
Documented behavior. Please read the section on UNION for the why and the proper alternative syntax: http://www.postgresql.org/docs/9.0/interactive/sql-select.html On Mar 28, 2012, at 7:01, Gary Stainburn wrote: > Hi folks. > > I have two selects which in themselves report what they should.

Re: [SQL] Postgresql function which compares values from both tables

2012-03-19 Thread David Johnston
> -Original Message- > From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql- > ow...@postgresql.org] On Behalf Of Richard Huxton > Sent: Monday, March 19, 2012 4:59 PM > To: David Johnston > Cc: 'Rehan Saleem'; pgsql-sql@postgresql.org > Subject: Re:

Re: [SQL] Postgresql function which compares values from both tables

2012-03-19 Thread David Johnston
You would need to install the "HSTORE" extension to convert the record into a key->value pair then perform the comparison on that. Dave From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Rehan Saleem Sent: Monday, March 19, 2012 3:40 PM To: pgsql-sq

Re: [SQL] help on a function with exception

2012-03-14 Thread David Johnston
On Mar 13, 2012, at 14:29, "M. D." wrote: > Hi, > > I want to do a check on a column if other columns meet certain conditions. > The program I'm working with allows to create additional columns on every > 'object' - called extra data, but I have no control over the program. I want > to enfor

Re: [SQL] Invalid syntax for integer

2012-03-13 Thread David Johnston
From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Rehan Saleem Sent: Tuesday, March 13, 2012 2:26 PM To: pgsql-sql@postgresql.org Subject: [SQL] Invalid syntax for integer hi , what is wrong with this if statement in this function if distance =''

Re: [SQL] Window function frame clause

2012-02-16 Thread David Johnston
On Feb 16, 2012, at 20:01, vpapavas wrote: > Hello all, > > I am trying to use this query in a toy database with customers and orders in > order to understand the capabilities of partitioning. In plain english what > I want to do is to select the orders of each customer and return only 3 of > t

Re: [SQL] need help with import

2012-02-15 Thread David Johnston
On Feb 15, 2012, at 21:05, Andreas wrote: > Am 16.02.2012 02:13, schrieb David Johnston: >> -Original Message- >> From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] >> On Behalf Of Andreas >> Sent: Wednesday, February 15, 20

Re: [SQL] need help with import

2012-02-15 Thread David Johnston
-Original Message- From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Andreas Sent: Wednesday, February 15, 2012 8:03 PM To: pgsql-sql@postgresql.org Subject: [SQL] need help with import Hi I get CSV files to import. Th structure is like this. main p

Re: [SQL] update column with multiple values

2012-02-10 Thread David Johnston
-Original Message- From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of ssylla Sent: Wednesday, February 08, 2012 9:31 PM To: pgsql-sql@postgresql.org Subject: [SQL] update column with multiple values Dear list, sorry, I already posted this, but it did

Re: [SQL] Multiple tables query on Mapserver

2012-02-01 Thread David Johnston
On Feb 2, 2012, at 0:32, tiplip wrote: > I just need gid or id in increasing order start from 0 (or 1), fetching their > original gid (or id) value is not necessary:) > can I do that? > > > David Johnston wrote >> >> >> The general method is to use "

Re: [SQL] Multiple tables query on Mapserver

2012-02-01 Thread David Johnston
On Feb 2, 2012, at 0:16, tiplip wrote: > Hi all, > > I have a couple of tables with same structure but standing for different > layers(1,2,3...) respectivle for Mapserver, > > table1 >gid| id| name | address| post code | layer > | geom > ---+--+---

Re: [SQL] must appear in the GROUP BY clause or be used in an aggregate function problem

2012-01-31 Thread David Johnston
-Original Message- From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Edward W. Rouse Sent: Tuesday, January 31, 2012 3:27 PM To: pgsql-sql@postgresql.org Subject: [SQL] must appear in the GROUP BY clause or be used in an aggregate function problem At

Re: [SQL] Update Mass Data in Field?

2012-01-26 Thread David Johnston
-Original Message- From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Carlos Mennens Sent: Thursday, January 26, 2012 6:59 PM To: PostgreSQL (SQL) Subject: [SQL] Update Mass Data in Field? I'm new to SQL so I'm looking for a way to change several emai

Re: [SQL] sql query problem

2012-01-17 Thread David Johnston
On Jan 17, 2012, at 8:35, Andreas Kretschmer wrote: > Alok Thakur wrote: > >> Dear, >> >> I am trying to provide you as much details as possible. >> >> answer` ( >> `id` int(10) NOT NULL AUTO_INCREMENT, >> `question_id` int(10) NOT NULL, >> `user_id` int(10) NOT NULL, >> `answer` int(10)

Re: [SQL] Query Problem... Left OuterJoin / Tagging Issue

2012-01-13 Thread David Johnston
On Jan 12, 2012, at 23:31, John Tuliao wrote: > Hi, > > I've been working on this for quite awhile now and don't seem to get the > proper query. > > I have basically 4 tables. > > 1. Table john_test contains the numbers of the calls. > 2. Table john_country contains the country with prefix.

Re: [SQL] Unable To Modify Table

2012-01-12 Thread David Johnston
-Original Message- From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Adrian Klaver Sent: Thursday, January 12, 2012 11:55 AM To: pgsql-sql@postgresql.org Cc: Carlos Mennens Subject: Re: [SQL] Unable To Modify Table > > How does one accomplish my goal

Re: [SQL] Unable To Modify Table

2012-01-12 Thread David Johnston
-Original Message- From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Carlos Mennens Sent: Thursday, January 12, 2012 11:43 AM To: PostgreSQL (SQL) Subject: [SQL] Unable To Modify Table I seem to have an issue where I can't modify a table due to anoth

Re: [SQL] Unable To Alter Data Type

2012-01-11 Thread David Johnston
On Jan 11, 2012, at 19:30, Carlos Mennens wrote: > On Wed, Jan 11, 2012 at 7:13 PM, David Johnston wrote: >> However, I will say again, you DO NOT WANT TO ACTUALLY DO THIS! >> >> The specific issue is that some US Postal Code begin with a zero ( 0 ) and >> so whenev

Re: [SQL] Unable To Alter Data Type

2012-01-11 Thread David Johnston
-Original Message- From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Carlos Mennens Sent: Wednesday, January 11, 2012 6:53 PM To: PostgreSQL (SQL) Subject: [SQL] Unable To Alter Data Type Now I'm attempting to ALTER the field 'cust_zip' TYPE from ch

Re: [SQL] Nested custom types: array - unable to insert

2011-12-30 Thread David Johnston
On Dec 30, 2011, at 21:53, John Poole wrote: > I am trying to create a custom data type for phone numbers where > I have a primary phone number and then an array of additional > phone numbers qualified by certain types. > > Below is a set of SQL commands I used to set up my custom > types. I a

Re: [SQL] Current transaction is aborted, commands ignored until end of transaction block

2011-12-29 Thread David Johnston
On Dec 29, 2011, at 23:25, Jan Bakuwel wrote: > Hi, > > Maybe there is a simple solution for PostgreSQL behaviour that is > annoying me... > > I've got users making updates to a master table and a number of detail > tables. All changes to the master record and related detail records are > encap

Re: [SQL] using a generated series in function

2011-12-17 Thread David Johnston
>From is not required if you use literals or function results (with literal >input parameters). If you reference something that is not one of these it has >to come from somewhere and that location is the from/join part of the query. In your query foo.work_date is not a literal or function and s

Re: [SQL] using a generated series in function

2011-12-15 Thread David Johnston
On Dec 15, 2011, at 23:16, John Fabiani wrote: > Hi, > > I am attempting (without success) use the generated series of dates that come > from: > select (cast(date_trunc('week', '2011-11-20'::date ) as date) + (i+6)) as > week_date from generate_series(0,84,7) i > > in a function. > select fu

Re: [SQL] conditional FROM

2011-12-10 Thread David Johnston
On Dec 10, 2011, at 11:03, Richard Klingler wrote: > Good day... > > I'm trying to build a query for PGSQL 9.1 where a table has two > references with only one being used depending of the type of entry.. > > For example, the table has following simplified structure: > >portidprima

Re: [SQL] prepared statements

2011-12-08 Thread David Johnston
-Original Message- From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Pavel Stehule Sent: Thursday, December 08, 2011 2:40 AM To: Vad N Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] prepared statements Hello 2011/12/8 Vad N : > > Hi. > > How can i

Re: [SQL] Change in 9.1?

2011-11-22 Thread David Johnston
-Original Message- From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Rob Sargent Sent: Tuesday, November 22, 2011 10:30 AM To: pgsql-sql@postgresql.org Subject: Re: [SQL] Change in 9.1? On 11/22/2011 12:39 AM, Jasmin Dizdarevic wrote: > Hi, > > we

Re: [SQL] clarification about ARRAY constructor implementation

2011-11-11 Thread David Johnston
On Nov 11, 2011, at 8:38, the6campbells wrote: > consider the following > > create table TARRBINT ( RNUM integer not null , CARRBINT bigint array[5] ) ; > > Can someone clarify why Postgres does not like examples 2, 6 and 7 An array must have a base type; an empty array has nothing with whi

Re: [SQL] Updatable view should truncate table fields

2011-11-08 Thread David Johnston
From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Russell Keane Sent: Tuesday, November 08, 2011 4:34 PM To: pgsql-sql@postgresql.org Subject: [SQL] Updatable view should truncate table fields Using PostgreSQL 9.0. We have a table which is not accessible by

Re: [SQL] Issue with a variable in a function

2011-11-08 Thread David Johnston
-Original Message- From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of tlund79 Sent: Tuesday, November 08, 2011 8:17 AM To: pgsql-sql@postgresql.org Subject: [SQL] Issue with a variable in a function The issue relates to the variable "prosjektkode" ($

Re: [SQL] the use of $$string$$

2011-11-04 Thread David Johnston
On Nov 4, 2011, at 11:26, John Fabiani wrote: > On Friday, November 04, 2011 07:38:29 am John Fabiani wrote: >> Hi, >> I just discovered that I can use $$string$$ to account for the problem of >> single quotes in the string (or other strange char's). However, I noticed >> that the table field co

Re: [SQL] Create Type with typmod_in

2011-11-04 Thread David Johnston
On Nov 4, 2011, at 10:01, Russell Keane wrote: > I’m trying to create a custom type (PostgreSQL 9.0) which will essentially > auto truncate a string to a certain length. > > > > > > Can this be done purely in plpgsql? > > If so, how? > > > An explicit cast of a value to varchar(n) ca

Re: [SQL] advice on how to store variable attributes

2011-10-25 Thread David Johnston
On Oct 22, 2011, at 10:07, Pavel Stehule wrote: > 2011/10/22 David Johnston : >> On Oct 22, 2011, at 6:41, Linos wrote: >> >>> Hi all, >>>i need a little of advice on what could be the best way to store this >>> information. >>> >&

Re: [SQL] Handling mutliple clients access with views

2011-10-24 Thread David Johnston
On Oct 24, 2011, at 22:54, Craig Ringer wrote: > On 25/10/11 03:23, Brice André wrote: >> Hello everyone, >> >> I am developping a web service where some tables are handling the data >> of different clients. Depending on configured rights, one client can >> have no access, or read access, or rea

Re: [SQL] advice on how to store variable attributes

2011-10-22 Thread David Johnston
On Oct 22, 2011, at 11:39, Linos wrote: > El 22/10/11 14:53, David Johnston escribió: >> On Oct 22, 2011, at 6:41, Linos wrote: >> >>> Hi all, >>> i need a little of advice on what could be the best way to store this >>> information. >>> &

Re: [SQL] advice on how to store variable attributes

2011-10-22 Thread David Johnston
On Oct 22, 2011, at 6:41, Linos wrote: > Hi all, >i need a little of advice on what could be the best way to store this > information. > > We need to calculate the difference in costs for our operations, we are > already > storing our vendor invoices in the database so calculate the moneta

Re: [SQL] plpgsql function executed multiple times for each return value

2011-10-08 Thread David Johnston
> So my questions are: 1) How do we cause the paymentcalc function to be > executed only once? and 2) How do we call a table returning function with > inputs from a table? > > Thank you very much! > > Steve > WITH func AS ( SELECT FUNC(...) AS func_result FROM ... ) SELECT (func.func_re

Re: [SQL] Sorting of data from two tables

2011-09-25 Thread David Johnston
On Sep 25, 2011, at 12:37, "R. Smith" wrote: > On Sat, Sep 17, 2011 at 2:56 PM, David Johnston wrote: >> On Sep 17, 2011, at 9:32, "R. Smith" wrote: >> >> >> What I want to do is do a query joining table A with B and sorting >> firstly on

Re: [SQL] using the aggregate function max()

2011-09-22 Thread David Johnston
On Sep 22, 2011, at 22:49, John Fabiani wrote: > Hi, > I need a little help understanding how to attack this problem. > > I need to find the max(date) of a field but I need that value later in my > query. > > If I > select max(x.date_field) as special_date from (select date_field) from tab

Re: [SQL] ambiguous local variable name in 9.0 proc

2011-09-21 Thread David Johnston
From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Samuel Gendler Sent: Wednesday, September 21, 2011 7:35 PM To: pgsql-sql@postgresql.org Subject: [SQL] ambiguous local variable name in 9.0 proc I've got a stored proc (which worked fine in 8.3 and 8.4)

Re: [SQL] Combining several CTEs with a recursive CTE

2011-09-20 Thread David Johnston
On Sep 20, 2011, at 5:58, Thomas Kellerer wrote: > > I'm just wondering if this is intended behavioury, simply not (yet) > implemented or even invalid according to the standard? I didn't find any > reference that it's not allowed in the manual. > > Regards > Thomas > > Try sticking the rec

Re: [SQL] Sorting of data from two tables

2011-09-17 Thread David Johnston
On Sep 17, 2011, at 9:32, "R. Smith" wrote: > > What I want to do is do a query joining table A with B and sorting > firstly on a field in Table A then on several fields in Table B. > > > SELECT a.gdn_gdn, a.gdn_custref, a.gdn_date, a.gdn_address_name, > a.gdn_method, b.gdn_stockref, b.gdn_row

Re: [SQL] Schema partitioning

2011-09-02 Thread David Johnston
On Sep 1, 2011, at 14:13, Charlie wrote: > Could I get feedback from the community on schema partitioning? > > I'm doing maintenance on my ddl and I'm noticing that my tables are all in 1 > schema, but they have prefixes on their names like table_app1_sometable, > table_app1_secondtable, ta

Re: [SQL] function based index problem

2011-08-31 Thread David Johnston
From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Viktor Bojovic Sent: Wednesday, August 31, 2011 5:27 PM To: pgsql-sql@postgresql.org; pgsql-ad...@postgresql.org Subject: [SQL] function based index problem Hi, on table entry (17M records) there is on

Re: [SQL] Add one column to another

2011-08-25 Thread David Johnston
I have to deal with a table which contains: first_name surname email1 email2 ... and I would like to create a view which combines both email columns thus: first_name surname email It looks simple but I can't think of an obvious query. ---

Re: [SQL] which is better: using OR clauses or UNION?

2011-08-16 Thread David Johnston
-Original Message- From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of adam_pgsql Sent: Tuesday, August 16, 2011 7:39 AM To: pgsql-sql Subject: [SQL] which is better: using OR clauses or UNION? Hi, I have a query hitting a table of 25 million rows. T

  1   2   >