Arrays in pgsql

Started by Martina Mostertabout 24 years ago4 messagesgeneral
Jump to latest
#1Martina Mostert
martina_mostert@gmx.de

Hallo,
I'm working on a plpgsql-function. I need an array of type integer. The
Programmer's Guide says 'PL/pgSQL variables can have any SQL datatype',
so I'd say there should also be arrays - or am I wrong?

Therefore I've got the following line in my code:

monthday integer[12];

But when running I always get 'ERROR: parse error at or near "["'.

Any suggestions?

Martina

#2Gregory Wood
gregw@com-stock.com
In reply to: Martina Mostert (#1)
Re: Arrays in pgsql

I'm working on a plpgsql-function. I need an array of type integer. The
Programmer's Guide says 'PL/pgSQL variables can have any SQL datatype',
so I'd say there should also be arrays - or am I wrong?

You'd be wrong... arrays are *not* an SQL datatype. Arrays are a PostgreSQL
construct.

monthday integer[12];

Any suggestions?

The closest thing I can come up with is creating a simple table with an
integer array column as a template, then you can declare a variable with a
TYPE matching that table. For example:

CREATE TABLE int_array_table (int_array integer[12]);

Then you can say:

monthday int_array_table.int_array%TYPE

But to be honest, I haven't tried this, so I can't say if it works or not.

Greg

#3Martina Mostert
martina_mostert@gmx.de
In reply to: Martina Mostert (#1)
Re: Arrays in pgsql

Thank you, I'll tell you if it works.

Gregory Wood wrote:

Show quoted text

I'm working on a plpgsql-function. I need an array of type integer. The
Programmer's Guide says 'PL/pgSQL variables can have any SQL datatype',
so I'd say there should also be arrays - or am I wrong?

You'd be wrong... arrays are *not* an SQL datatype. Arrays are a PostgreSQL
construct.

monthday integer[12];

Any suggestions?

The closest thing I can come up with is creating a simple table with an
integer array column as a template, then you can declare a variable with a
TYPE matching that table. For example:

CREATE TABLE int_array_table (int_array integer[12]);

Then you can say:

monthday int_array_table.int_array%TYPE

But to be honest, I haven't tried this, so I can't say if it works or not.

Greg

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Martina Mostert (#1)
Re: Arrays in pgsql

Martina Mostert <martina_mostert@gmx.de> writes:

Therefore I've got the following line in my code:
monthday integer[12];
But when running I always get 'ERROR: parse error at or near "["'.

Update to PG 7.2.

regards, tom lane