Re: Cannot declare record members NOT NULL

From: Osvaldo Rosario Kussama <osvaldo_kussama(at)yahoo(dot)com(dot)br>
To: Cultural Sublimation <cultural_sublimation(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Cannot declare record members NOT NULL
Date: 2007-09-12 21:00:17
Message-ID: 46E85361.3000703@yahoo.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Cultural Sublimation escreveu:
> Hi,
>
> I am not sure if this qualifies as a bug report or a feature request,
> but I don't see any way to tell Postgresql that the members of a record
> cannot be NULL. This causes all kinds of problems when this record
> is used to declare the return type of a function. Suppose I had the
> following table: (note that all columns are NOT NULL)
>
> CREATE TABLE movies
> (
> movie_id int4 UNIQUE NOT NULL,
> movie_name text NOT NULL,
> PRIMARY KEY (movie_id)
> );
>
>
> Suppose also that I didn't want the clients to query the table directly,
> but instead they have to go through a function "get_movies" which returned
> a record of type "get_movies_t":
>
> CREATE TYPE get_movies_t AS
> (
> movie_id int4,
> movie_name text
> );
>
>
> CREATE FUNCTION get_movies ()
> RETURNS SETOF get_movies_t
> LANGUAGE sql STABLE
> AS
> $$
> SELECT movie_id, movie_name FROM movies;
> $$;
>
>
> The problem is that Postgresql tells the client that the function returns
> two columns, both of which can be NULL, and this makes a mess on the
> client side. Is there anyway I can tell Postgresql that the columns of
> get_movies_t are NOT NULL?
>
> If this is (yet another) defect in the SQL standard, can someone suggest
> an alternative that would get around it?
>

CREATE FUNCTION get_movies ()
RETURNS SETOF get_movies_t
LANGUAGE sql STABLE
AS
$$
SELECT movie_id, movie_name FROM movies
WHERE movie_id NOT NULL AND movie_name NOT NULL;
$$

Osvaldo

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Cultural Sublimation 2007-09-12 21:22:46 Re: Cannot declare record members NOT NULL
Previous Message shakahshakah@gmail.com 2007-09-12 20:54:31 Re: Event-driven programming?