使用PHP插入自定义Postgres数据类型

时间:2010-07-01 00:44:27

标签: php postgresql insert types

CREATE TYPE mpaa_rating AS ENUM (
    'G',
    'PG',
    'PG-13'
);

CREATE TABLE film (
    film_id integer DEFAULT nextval('film_film_id_seq'::regclass) NOT NULL,
    rating mpaa_rating DEFAULT 'G'::mpaa_rating
);

我尝试了以下内容:

  1. pg_insert($dbconn, "film", new array("rating" => "PG"));
  2. pg_insert($dbconn, "film", new array("rating" => "'PG'::mpaa_rating"));
  3. pg_insert($dbconn, "film", new array("rating" => "PG::mpaa_rating"));
  4. 我收到错误: unknown or system data type

1 个答案:

答案 0 :(得分:1)

pg_query($dbconn, "insert into film(rating) values('PG');");

pg_insert是实验性的,有几个缺点。