---
name: "Rose::DB::Pg"
section: "3pm"
platform: "linux"
package: "librose-db-perl"
version: "0.786-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Rose::DB::Pg"
---

# Rose::DB::Pg(3pm)

PostgreSQL driver class for Rose::DB.

## NAME

Rose::DB::Pg - PostgreSQL driver class for Rose::DB.

## SYNOPSIS

```
  use Rose::DB;
  Rose::DB->register_db(
    domain   => 'development',
    type     => 'main',
    driver   => 'Pg',
    database => 'dev_db',
    host     => 'localhost',
    username => 'devuser',
    password => 'mysecret',
    server_time_zone => 'UTC',
    european_dates   => 1,
  );
  Rose::DB->default_domain('development');
  Rose::DB->default_type('main');
  ...
  $db = Rose::DB->new; # $db is really a Rose::DB::Pg-derived object
  ...
```

## DESCRIPTION

Rose::DB blesses objects into a class derived from Rose::DB::Pg when the driver is "pg".  This mapping of driver names to class names is configurable.  See the documentation for Rose::DB's **new()** and **driver\_class()** methods for more information.

This class cannot be used directly.  You must use Rose::DB and let its **new()** method return an object blessed into the appropriate class for you, according to its **driver\_class()** mappings.

Only the methods that are new or have different behaviors than those in Rose::DB are documented here.  See the Rose::DB documentation for the full list of methods.

## CLASS METHODS

- **timestamps\_are\_inlined \[BOOL\]**

  Get or set a boolean value that indicates whether or not timestamp keywords should be inline. If `"timestamps_are_inlined"` is true, then keywords such as CURRENT\_DATESTAMP and CURRENT\_TIMESTAMP are inlined in the generated SQL queries. The default is false.

## OBJECT METHODS

- **european\_dates \[BOOL\]**

  Get or set the boolean value that determines whether or not dates are assumed to be in european dd/mm/yyyy format.  The default is to assume US mm/dd/yyyy format (because this is the default for PostgreSQL).

  This value will be passed to DateTime::Format::Pg as the value of the `"european"` parameter in the call to the constructor `new()`.  This DateTime::Format::Pg object is used by Rose::DB::Pg to parse and format date-related column values in methods like parse\_date, format\_date, etc.

- **next\_value\_in\_sequence SEQUENCE**

  Advance the sequence named SEQUENCE and return the new value.  Returns undef if there was an error.

- **server\_time\_zone \[TZ\]**

  Get or set the time zone used by the database server software.  TZ should be a time zone name that is understood by DateTime::TimeZone.  The default value is "floating".

  This value will be passed to DateTime::Format::Pg as the value of the `"server_tz"` parameter in the call to the constructor `new()`.  This DateTime::Format::Pg object is used by Rose::DB::Pg to parse and format date-related column values in methods like parse\_date, format\_date, etc.

  See the DateTime::TimeZone documentation for acceptable values of TZ.

- **pg\_enable\_utf8 \[BOOL\]**

  Get or set the pg\_enable\_utf8 database handle attribute.  This is set directly on the dbh, if one exists.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::Pg chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::Pg documentation to learn more about this attribute.

- **sslmode \[MODE\]**

  Get or set the SSL mode of the connection.  Valid values for MODE are `"disable"`, `"allow"`, `"prefer"`, and `"require"`.  This attribute is used to build the DBI dsn.  Setting it has no effect until the next connection.  See the DBD::Pg documentation to learn more about this attribute.

### Value Parsing and Formatting

- **format\_array ARRAYREF \| LIST**

  Given a reference to an array or a list of values, return a string formatted according to the rules of PostgreSQL's "ARRAY" column type.  Undef is returned if ARRAYREF points to an empty array or if LIST is not passed.

- **format\_interval DURATION**

  Given a DateTime::Duration object, return a string formatted according to the rules of PostgreSQL's "INTERVAL" column type.  If DURATION is undefined, a DateTime::Duration object, a valid interval keyword (according to validate\_interval\_keyword), or if it looks like a function call (matches `"/^\w+\(.*\)$/"`) and keyword\_function\_calls is true, then it is returned unmodified.

- **parse\_array STRING**

  Parse STRING and return a reference to an array.  STRING should be formatted according to PostgreSQL's "ARRAY" data type.  Undef is returned if STRING is undefined.

- **parse\_interval STRING**

  Parse STRING and return a DateTime::Duration object.  STRING should be formatted according to the PostgreSQL native "interval" (years, months, days, hours, minutes, seconds) data type.

  If STRING is a DateTime::Duration object, a valid interval keyword (according to validate\_interval\_keyword), or if it looks like a function call (matches `"/^\w+\(.*\)$/"`) and keyword\_function\_calls is true, then it is returned unmodified.  Otherwise, undef is returned if STRING could not be parsed as a valid "interval" value.

- **validate\_date\_keyword STRING**

  Returns true if STRING is a valid keyword for the PostgreSQL "date" data type.  Valid (case-insensitive) date keywords are:

  ```
      current_date
      epoch
      now
      now()
      today
      tomorrow
      yesterday
  ```

  The keywords are case sensitive.  Any string that looks like a function call (matches `"/^\w+\(.*\)$/"`) is also considered a valid date keyword if keyword\_function\_calls is true.

- **validate\_datetime\_keyword STRING**

  Returns true if STRING is a valid keyword for the PostgreSQL "datetime" data type, false otherwise.  Valid (case-insensitive) datetime keywords are:

  ```
      -infinity
      allballs
      current_date
      current_time
      current_time()
      current_timestamp
      current_timestamp()
      epoch
      infinity
      localtime
      localtime()
      localtimestamp
      localtimestamp()
      now
      now()
      timeofday()
      today
      tomorrow
      yesterday
  ```

  The keywords are case sensitive.  Any string that looks like a function call (matches `"/^\w+\(.*\)$/"`) is also considered a valid datetime keyword if keyword\_function\_calls is true.

- **validate\_time\_keyword STRING**

  Returns true if STRING is a valid keyword for the PostgreSQL "time" data type, false otherwise.  Valid (case-insensitive) timestamp keywords are:

  ```
      allballs
      current_time
      current_time()
      localtime
      localtime()
      now
      now()
      timeofday()
  ```

  The keywords are case sensitive.  Any string that looks like a function call (matches `"/^\w+\(.*\)$/"`) is also considered a valid timestamp keyword if keyword\_function\_calls is true.

- **validate\_timestamp\_keyword STRING**

  Returns true if STRING is a valid keyword for the PostgreSQL "timestamp" data type, false otherwise.  Valid (case-insensitive) timestamp keywords are:

  ```
      -infinity
      allballs
      current_date
      current_time
      current_time()
      current_timestamp
      current_timestamp()
      epoch
      infinity
      localtime
      localtime()
      localtimestamp
      localtimestamp()
      now
      now()
      timeofday()
      today
      tomorrow
      yesterday
  ```

  The keywords are case sensitive.  Any string that looks like a function call (matches `"/^\w+\(.*\)$/"`) is also considered a valid timestamp keyword if keyword\_function\_calls is true.

## AUTHOR

John C. Siracusa (siracusa@gmail.com)

## LICENSE

Copyright (c) 2010 by John C. Siracusa.  All rights reserved.  This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
