[SQL] Writeable CTE Not Working?

2013-01-28 Thread Kong Man
Can someone explain how this writable CTE works? Or does it not? What I tried to do was to make those non-null/non-empty values of suppliers.suppliercode unique by (1) nullifying any blank, but non-null, suppliercode, then (2) appending the supplierid values to the suppliercode values for tho

Re: [SQL] Writeable CTE Not Working?

2013-01-29 Thread Kong Man
Hi Victor, > I see 2 problems with this query: > 1) CTE is just a named subquery, in your query I see no reference to > the “upd_code” CTE. >Therefore it is never gets called; So, in conclusion, my misconception about CTE in general was that all CTE get called without being referenced. Tha

Re: [SQL] Writeable CTE Not Working?

2013-01-29 Thread Kong Man
> I think this explanation is wrong --- if you run the query with EXPLAIN > ANALYZE, you can see from the rowcounts that the writable CTE *does* get > run to completion, as indeed is stated to be the behavior in the fine > manual. > > However, for a case like this where the main query isn't readi

[SQL] Data Loss from SQL SELECT (vs. COPY/pg_dump)

2013-04-05 Thread Kong Man
I am troubled to find out that a SELECT statement produces fewer rows than the actual row count and have not been able to answer myself as to why. I hope someone could help shedding some light to this. I attempted to generate a set of INSERT statements, using a the following SELECT statement,

Re: [SQL] Data Loss from SQL SELECT (vs. COPY/pg_dump)

2013-04-05 Thread Kong Man
This seems to answer my question. I completely forgot about the behavior of NULL value in the text concatenation. http://www.postgresql.org/docs/9.1/static/plpgsql-statements.html#PLPGSQL-QUOTE-LITERAL-EXAMPLE Because quote_literal is labelled STRICT, it will always return null when calle