Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fixes issue #7914 - PostgreSQL adapter doesn't fetch column defaults when using multiple schemas and domains #7937

merged 4 commits into from Oct 14, 2012


None yet
2 participants

arturopie commented Oct 14, 2012

Please, read issue #7914 for details about the bug, and commit messages for details about the fix and changes.

Let me know what branches you want me to backport the changes to.



arturopie added some commits Oct 12, 2012

#7914 get default value when type uses schema name
PostgreSQL adapter properly parses default values when using multiple
schemas and domains.

When using domains across schemas, PostgresSQL prefixes the type of the
default value with the name of the schema where that type (or domain) is.

For example, this query:
SELECT a.attname, d.adsrc
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = "defaults"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum;

could return something like "'<default_value>'::pg_catalog.text" or
"(''<default_value>'::pg_catalog.text)::text" for the text columns with

I modified the regexp used to parse this value so that it ignores
anything between ':: and \b(?:character varying|bpchar|text), and it
allows to have optional parens like in the above second example.
#7914 Using a better way to get the defaults from db.
According to postgreSQL documentation:
we should not be using 'adsrc' field because this field is unaware of
outside changes that could affect the way that default values are
represented. Thus, I changed the queries to use
"pg_get_expr(adbin, adrelid)" instead of the historical "adsrc" field.
#7914 Remove code for unsupported postgreSQL version.
Remove parsing of character type default values for 8.1 formatting since
Rails doesn't support postgreSQL 8.1 anymore.

Remove misleading comment unrelated to code.

rafaelfranca added a commit that referenced this pull request Oct 14, 2012

Merge pull request #7937 from arturopie/7914-defaults-on-domains-and-…

Fixes #7914 - PostgreSQL adapter doesn't fetch column defaults when using multiple schemas and domains

@rafaelfranca rafaelfranca merged commit ca618d4 into rails:master Oct 14, 2012


rafaelfranca commented Oct 14, 2012

Thank you.

Is not easy to backport this fix to 3-2-stable. Could you open a new pull request to it?


arturopie commented Oct 14, 2012

Sure, what about 3-1-stable and 3-0-stable?


rafaelfranca commented Oct 14, 2012

The only branch that we are supporting is 3-2-stable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment