pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Assigning Values to Composite Types
2+ messages / 2 participants
[nested] [flat]

* Assigning Values to Composite Types
@ 2009-10-22 17:31 Gary Chambers <gwchamb@gmail.com>
  2009-10-22 18:28 ` Re: Assigning Values to Composite Types Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: Gary Chambers @ 2009-10-22 17:31 UTC (permalink / raw)
  To: pgsql-sql

All...

Given the following [hopefully] relevant portions of a function:

CREATE OR REPLACE FUNCTION solve(FLOAT8, VARCHAR, CHAR)
RETURNS SETOF sometype_t AS
$solve$
DECLARE
    data sometype_t;
...

BEGIN
    FOR term_count IN
        SELECT DISTINCT coord_type AS coord_type, MAX(term) AS maxterms
        ...
    LOOP
        FOR i IN 0 .. term_count.maxterms LOOP
            SELECT SUM(a + b + c) INTO Q
            ...
            S := S + (Q * onevalue * somevalue);
        END LOOP;
        -- This is the only means of verifying/viewing the data
        RAISE NOTICE '% = %', term_count.coord_type, S;

        /* Here is where I am stuck trying to fill data
           I've tried:

           data.term_count.coord_type := S;
           (data.term_count).coord_type := S;
           data.(term_count.coord_type) := S;
        */

        S := 0.0;
    END LOOP;
    RETURN NEXT vsop87_data;
END;
$solve$ LANGUAGE plpgsql STRICT IMMUTABLE;

Is there a means of filling something.something.something with a value
so I can get all the values into a single row?  Thanks very much in
advance.

-- Gary Chambers

/* Nothing fancy and nothing Microsoft! */



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Assigning Values to Composite Types
  2009-10-22 17:31 Assigning Values to Composite Types Gary Chambers <gwchamb@gmail.com>
@ 2009-10-22 18:28 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2009-10-22 18:28 UTC (permalink / raw)
  To: Gary Chambers <gwchamb@gmail.com>; +Cc: pgsql-sql

Gary Chambers <gwchamb@gmail.com> writes:
>         /* Here is where I am stuck trying to fill data
>            I've tried:

>            data.term_count.coord_type := S;
>            (data.term_count).coord_type := S;
>            data.(term_count.coord_type) := S;
>         */

I'm afraid plpgsql isn't tremendously bright about such cases.  If
you have all the values available at once, though, it seems like
you should be able to do

	data.term_count := row(this, that, the_other);

An explicit cast of the row() construct to the target column's type
might be a good idea --- I think it would work without, but probably
not with good performance.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2009-10-22 18:28 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-10-22 17:31 Assigning Values to Composite Types Gary Chambers <gwchamb@gmail.com>
2009-10-22 18:28 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox