Re: Equivalent syntax of PL/SQL using array in PL/pgSQL

From: Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>
To: Dang Minh Huong <kakalot49(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Equivalent syntax of PL/SQL using array in PL/pgSQL
Date: 2013-11-14 18:40:24
Message-ID: CAL_0b1vovW6x_rGYobiDa1C26JoupG8bYDwPuMM=9azgYBRTZg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Nov 14, 2013 at 7:13 AM, Dang Minh Huong <kakalot49(at)gmail(dot)com> wrote:
> I am using PostgreSQL 9.1 and get a syntax error with the following PL/pgSQL clause.
> Is there any equivalent syntax in PL/pgSQL to solve it.
>
> ------
> rec typ[];
> (typ[1]).t1 := 1;
> ------

You can easily make different tricks with records using the hstore
module [1]. Just like this:

[local]:5432 grayhemp(at)grayhemp=# \d a
Table "public.a"
Column | Type | Modifiers
--------+---------+-----------
id | integer | not null
n | name |

[local]:5432 grayhemp(at)grayhemp=# do $$
declare rec a[];
begin
rec[1] := (1, 'a')::a;
rec[2] := (2, 'b')::a;
rec[1] := rec[1] #= (hstore('id', 3::text) || hstore('n', null));
raise info '% %', rec[1].id, rec[1].n;
end $$;
INFO: 3 <NULL>
DO

[1] http://www.postgresql.org/docs/9.3/static/hstore.html

--
Kind regards,
Sergey Konoplev
PostgreSQL Consultant and DBA

http://www.linkedin.com/in/grayhemp
+1 (415) 867-9984, +7 (901) 903-0499, +7 (988) 888-1979
gray(dot)ru(at)gmail(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Helio Campos Mello de Andrade 2013-11-14 18:42:15 PostgreSQL now on Amazon RDS
Previous Message Sergey Konoplev 2013-11-14 18:11:25 Re: Tuning 9.3 for 32 GB RAM